Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 533715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:32:14+00:00 2026-05-13T09:32:14+00:00

I looked the site to find a solution for my problem, but couldn’t find

  • 0

I looked the site to find a solution for my problem, but couldn’t find the answer. Hopefully someone can help me with this:

I have a script that uploads and resizes an image without pagerefresh. I found it on the internet and adjusted it for my use. The script can be found underneath.

My problem:

First the upload.php script worked, but know I get error number 9.

What did I do to try to solve it myself:

  1. Tried it on a localmachine and on a server, both give the same error number 9
  2. Removed all the $_POST and set ‘static’ vars, didn’t work and still got number 9

Can someone please help me, tnx in advance

Grtzzz

Wim

upload.php

<?php
/************************************************************            
 *-----------------------------------------------------------
 * Version  : 0.2
 * Author  : Wim Selles        
 * Date  : 2009-12-04
 * History  : Adjusted to use with AJAX upload
 *     Added check for allowed extension
 *     Added change filename to time 
 *     of uploading
 *-----------------------------------------------------------
 * Version  : 0.1
 * Author  : Eris        
 * Date  : 2005-11-19
 * History  : Initial version
 * Source  : http://www.phphulp.nl/php/scripts/9/464/
 *-----------------------------------------------------------
 ************************************************************/

if(!empty($_FILES['file'])){
 //---- filename generated by the server when uploading a file
 $tempfile     =  $_FILES['file']['tmp_name'];
 //---- directory with the final location 
 $dir      =  $_POST['uploadPath'];
 //---- Get the extension of the file    
 $ext      =  strtolower(substr(strrchr($_FILES['file']['name'], '.'), 1));
 $ext_image    =  array("gif", "jpg","jpeg","png");
 //---- new filename is time and extention
 $file      =  time().".".$ext;
 //---- resize / max height and width of image
 list($height,$width) = explode(',',$_POST['imageMess']);
 //---- The max filesize
 $limit_size    = $_POST['imageSize']*1024*1024;

 //---- error = 1 => file is not uploaded
 //---- error = 2 => No image file
 //---- error = 3 => File uploaded
 //---- error = 4 => Error during move upload file
 //---- error = 5 => File allready exsits
 //---- error = 6 => Error resizing jpg
 //---- error = 7 => Error resizing gif
 //---- error = 8 => Error resizing png
 //---- error = 9 => Imagecreate error for jpg
 //---- error = 10 => Resized (not error, but succes ;-))
 //---- error = 11 => Imagecreate error for gif 
 //---- error = 12 => Imagecreate error for png 
 //---- error = 13 => Filetype not allowed

 //----check if the file is realy uploaded
 if(filesize($tempfile)>=$limit_size){
  $error = 14;
 }elseif(!is_uploaded_file($tempfile)){
  $error = 1;
 }elseif(!in_array($ext, $ext_image)){
  //---- Check if file is allowed, if not, then show error
  $error = 13;
 }else{
  //---- get the dimensions of the file
  if(!$dim = getimagesize($tempfile)){
   $error = 2;
  }else{    
   //---- 0 = width 
   //---- 1 = height
   //---- 2 = type
   //---- we want to calculte if it is bigger then the maxsize if not keep it easy --> upload it
   if($dim[0] < $width && $dim[1] < $height){
    //----move upload file
    if(!file_exists($dir.$file)){
     if(@move_uploaded_file($tempfile,$dir.$file)){
      $error = 3;
     }else{
      $error = 4;    
     }
    }else{
     $error = 5;   
    }        
   }else{
    //---- we have to resize :(
    if($dim[0] > $dim[1]){
     $prop = $width / $dim[0];
     $dims[0] = $width;
     $dims[1] = round($dim[1] * $prop); 
    }else{
     $prop = $height / $dim[1];
     $dims[1] = $height;
     $dims[0] = round($dim[0] * $prop); 
    }
    //---- we know the new size
    if($dim[2] == 2){
     if(!$mimage = @imagecreatefromjpeg($tempfile)){
      $error = 6;
     }
    }
    //---- we know the new size
    if($dim[2] == 1){
     if(!$mimage = @imagecreatefromgif($tempfile)){
      $error = 7;
     }
    }
    //---- we know the new size
    if($dim[2] == 3){
     if(!$mimage = @imagecreatefrompng($tempfile)){
      $error = 8;
     }
    }
    $im = @imagecreatetruecolor($dims[0],$dims[1]);
    @imagecopyresampled($im, $mimage, 0, 0, 0, 0, $dims[0], $dims[1], $dim[0], $dim[1]);

    if(!file_exists($dir.$file)){
     if($dim[2] == 2){
      if(!@imagejpeg($im,$dir.$file,100)){
       $error = 9; // This is the error i still get
      }else{
       $error = 10;    
      }    
     }    
     if($dim[2] == 1){
      if(!@imagegif($im,$dir.$file)){
       $error = 11;
      }else{
       $error = 10;    
      }    
     }

     if($dim[2] == 3){
      if(!@imagepng($im,$dir.$file)){
       $error = 12;
      }else{
       $error = 10;      
      }    
       }
    }else{
     $error = 5;       
    }
    imagedestroy($im);
    imagedestroy($mimage);  
    //---- end resize
   }  
  }
 }
 ?>

 <script language="javascript" type="text/javascript">
     parent.stopUpload(<?php echo $error; ?>,'<?php echo "intranet/admin/uploadedImages/".$file;?>');
  //alert(<?php //echo $error2;?>);
    </script>

    <?php
}
?>

JS file:

$(document).ready(function(){
 //---- When the button is clicked to submit the file
 $('#submitfile').submit(startUpload);
});

function startUpload(){
 $('#f1_upload_process').show();
 return true;
}
stopUpload=function (response, filename){
 //---- The upload errors
 var uploadError = new Array;
 uploadError[1] =  'Bestand is niet geupload';       // file is not uploaded
 uploadError[2] = 'Dit is geen afbeeldingsbestand';     // No image file
 uploadError[4] = 'Error tijdens het verplaatsen van het bestand'; // Error during move upload file
 uploadError[5] = 'Bestand bestaat reeds';        // File allready exsits
 uploadError[6] = 'Error tijdens het resizen van een jpg bestand'; // Error resizing jpg
 uploadError[7] = 'Error tijdens het resizen van een gif bestand'; // Error resizing gif
 uploadError[8] = 'Error tijdens het resizen van een png bestand'; // Error resizing png
 uploadError[9] = 'Error tijdens het creeeren van een jpg bestand'; // Imagecreate error for jpg
 uploadError[11] = 'Error tijdens het creeeren van een gif bestand'; // Imagecreate error for gif
 uploadError[12] = 'Error tijdens het creeeren van een png bestand'; // Imagecreate error for png
 uploadError[13] = 'Bestandstype niet toegestaan';      // Filetype not allowed
 uploadError[14] = 'Het bestand is te groot';       // File to big
 //---- If fileupload went good, insert image into RTE
 if (response == 3 || response == 10){
  //alert(filename);
  $('#profilePhoto').attr("src",filename);
  $('#f1_upload_process').hide();
  $('#result').html('');
  $('#fileLocation').val('');
  return false;
 } else {
  $('#f1_upload_process').hide();
  $('#result').html(uploadError[response]);
  //alert('Response= ' + response + ' New filename= ' + filename);
 }
 return true;
}

The form:

<form action="intranet/admin/upload.php" method="post" enctype="multipart/form-data" target="upload_target" id="submitfile">

                <img id="profilePhoto" src="intranet/admin/uploadedImages/unknown.png" height="100px"/>

                <img id="f1_upload_process" src="include/css/images/ajax-loader3.gif" />

                <br />
    <br />

    <input name="file" type="file" id="fileLocation" />
    <input type="submit" name="submitBtn" value="Upload" />

    <br />
    <br />

    <p class="text">Toegestane extensies: *.jpg | *.gif | *.png</p>

    <br />

    <p id="result"></p>

   </form>

   <iframe id="upload_target" name="upload_target" style="width:0;height:0;border:0px solid #fff;"></iframe>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:32:14+00:00Added an answer on May 13, 2026 at 9:32 am

    Try to remove the @ in this line:

     if(!@imagejpeg($im,$dir.$file,100)){
    

    It suppresses the error imagejpeg throws. Without it, you might see what your problem is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anyone looked into this recently? 12 months ago i was using Uploadify 6 months
I have looked a lot on google for answers of how to use the
I'm trying to code a site that will allow multiple people to be working
I'm in the process of rewriting all the URLs on my site that end
I was trying to go to http://lustiges-taschenbuch.de which is a valid comic book site.
This has been frustrating me for days now. I am trying to use Sharepoint
i would like to implement some kind of service my customers can use to
I'm wondering if it's possible to use jQuery's bind() to fire a custom event
Where would be the best place to put the edge length in an adjacency
I'm studying some Rails 3 code from Spree: module Spree module Generators class SiteGenerator

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.