Upload Image Function (old code?)

Hello,

I am trying to help someone with their website admin system that they had made back in 2009. When trying to add new items using this system, the new products did not have images like they used to. I traced the problem and realized that they weren’t even being uploaded to the FTP server. The people who made the website use the following function to upload the images. I am assuming the problem has to do with the fact that some of the code has been deprecated, as it was written for an earlier version of PHP. Just for reference the version of PHP currently installed on the website is PHP Version 5.3.8. Hopefully that explains the problem!

Here is the code:

[php]function upload_image($uploading_file, $uploaddir, $new_imagename)
{

// print_r($_FILES);

           $thumb_path             = $uploaddir."/thumb";
           $thumb_img              = $thumb_path . "/" .$new_imagename;
           $display_path   = $uploaddir."/display";
           $display_img    = $display_path . "/" .$new_imagename;

           $message = "<br /><strong>Image Upload</strong>";

           if(!isset($_FILES) && isset($HTTP_POST_FILES))
           $_FILES = $HTTP_POST_FILES;

           if($_FILES[$uploading_file]['size'] >= MAXSIZE)
           $error[$uploading_file] = "<br />The image file exceeds the limit.";

           if(!isset($_FILES[$uploading_file]))
           $error[$uploading_file] = "<br />An image was not found.";

           $imagename = basename($_FILES[$uploading_file]['name']);
           //echo $imagename;

           if(empty($imagename))
           $error[$uploading_file] = "<br />The name of the image was not found.";

           if(empty($error))
           {
                   $newimage = $uploaddir . "/" . $new_imagename;

                   //echo $newimage;
                   $result = @move_uploaded_file($_FILES[$uploading_file]['tmp_name'], $newimage);

                   // CONVERT IMAGE TO THUMB
                   if(is_dir($thumb_path))
                   exec ("convert $newimage -resize ".T_RESIZE_W."x".T_RESIZE_H." $thumb_img");

                   // CONVERT IMAGE TO DISPLAY
                   if(is_dir($display_path))
                   exec ("convert $newimage -resize ".RESIZE_W."x".RESIZE_H." $display_img");

                   if(empty($result))
                           $error["result"] = "<br />There was an error moving the uploaded file.";
           }

           if(!empty($error))
           {
                   while(list($key, $val) = each($error))
                   {
                           $message .= "<br />Upload Failed because of the following $val";
                   }
           }       else {
                   $message .= "<br /> Uploaded Successfully";
           }

           return $message;
   }

[/php]

Thank you very much for your assistance, and btw I am NOT getting paid to do this, I am helping a family member for free, or at least trying to help lol.

-Mike

didn’t see anything that jumped out at me…

See if you have the directories thumb and display on your server. Do they contain image files? Can you add an image and see it appear in both folders? Do they have write privileges?

I’d also have a look at the php error logs to see if it’s reporting a problem.

More information is needed to solve.

1.) The directories thumb and display are both on the server, and are CHMODed to 2775 (is this correct?).

2.) They contain the images that were uploaded correctly in 2009, but not the new images we are attempting to upload using the same process now (2012). So I can not add an image anymore, it does not get uploaded, it used to work and no code was changed from then to now.

3.) How can I check the PHP error logs?

Thank you very much.

I think the problem may lie in the fact that the images themselves don’t have the correct privileges. When the images are uploaded, they have the following privilege settings:

rw-r----- (0640)

If I manually change it to:

rw-rw-r-- (0664)

The images show up correctly.

How can I make the code I originally posted make sure the images are uploaded with the correct privileges? Strange that it once worked, but who cares, lol.

Sponsor our Newsletter | Privacy Policy | Terms of Service