Problem in uploading images.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
FacJoe
Forum Newbie
Posts: 8
Joined: Sun Dec 07, 2008 7:49 pm

Problem in uploading images.

Post by FacJoe »

I'm unsure where to put this query, so please, apologies if I posted on the wrong forum.

I'm working on a PHP site and I have a function that uploads the images. I did not do this site from scratch and I'm basically just tracing code that the other developer did. Here's the function:

Code: Select all

 
function imageUpload($uploaded_file)
  {
    echo "";
    // check for a successfully uploaded image
    if ($uploaded_file['error'] == UPLOAD_ERR_NO_FILE)
      return null;
    if ($uploaded_file['error'] != UPLOAD_ERR_OK)
      return 'The image did not upload correctly. Please try reducing the size of the file before uploading.';
 
    $src_fn = escapeshellarg($uploaded_file['tmp_name']);
 
    // check the uploaded image is a supported mime type
    $mime = exec("identify {$src_fn} 2>/dev/null");
 
if (!preg_match('/^.* (JPEG|PNG|GIF|TIFF) (\d+)x(\d+) /', $mime, $matches))
      return 'The uploaded image is not a supported image format, please upload a JPEG, GIF, TIFF or PNG file.';
.
.
.
}
 
The error occurs, I think on this line:

Code: Select all

 
exec("identify {$src_fn} 2>/dev/null");
 
It returns a $mime value of "" and I think it should return something.

The value of $uploaded_file are these:

$uploaded_file["name"] = "saveimageupload.jpg"
$uploaded_file["type"] = "image/pjpeg"
$uploaded_file["tmp_name"] = "image/pjpeg"
$uploaded_file["error"] = 0
$uploaded_file["size"] = 15327

I really don't know what the function "identify {} 2>/dev/null" does.

Thank you.
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: Problem in uploading images.

Post by it2051229 »

its my first time to encounter exec function and PHP documentation says that it executes an external program... how about if you temporarily comment it out or remove that line and give it a try.
nvartolomei
Forum Newbie
Posts: 11
Joined: Tue Jan 06, 2009 3:46 pm

Re: Problem in uploading images.

Post by nvartolomei »

try this

Code: Select all

function imageUpload($uploaded_file) {
    // check for a successfully uploaded image
    if ($uploaded_file['error'] == UPLOAD_ERR_NO_FILE)
        return null;
    if ($uploaded_file['error'] != UPLOAD_ERR_OK)
        return 'The image did not upload correctly. Please try reducing the size of the file before uploading.';
    $src_fn = escapeshellarg($uploaded_file['tmp_name']);
 
 // check the uploaded image is a supported mime type
    #$mime = exec("identify {$src_fn} 2>/dev/null");
    $mime = $uploaded_file['type'];
 
if (!preg_match('/^.* (JPEG|PNG|GIF|TIFF) (\d+)x(\d+) /', $mime, $matches))
      return 'The uploaded image is not a supported image format, please upload a JPEG, GIF, TIFF or PNG file.';
}
Post Reply