Page 1 of 1

Problem in uploading images.

Posted: Tue Jan 06, 2009 10:16 pm
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.

Re: Problem in uploading images.

Posted: Tue Jan 06, 2009 11:04 pm
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.

Re: Problem in uploading images.

Posted: Wed Jan 07, 2009 1:40 am
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.';
}