[UPHPU] File upload validation
Rusty Keele
rusty.keele at yahoo.com
Wed Jan 23 14:15:39 MST 2008
Trevyn Meyer <trevyn at esourcehome.com> wrote: Have you ever written a file upload validation? What methods seem to
work for you? I have tried PHP mime type, but ran into problems where
the OS thinks its one things and php thinks its another. I have some
jepgs uploaded that recive no mime type. I have also tried the linux
file command and it works ok, but with no great success.
I have used the exif functions in php to make sure users upload a specific image file type:
$imagetype = (exif_imagetype($_FILES['upload']['tmp_name']));
if($imagetype > 0)
{
if (($imagetype != IMAGETYPE_GIF) &&
($imagetype != IMAGETYPE_JPEG) &&
($imagetype != IMAGETYPE_PNG))
return 'Error: Attachment must be a gif, jpg or png';
}
else
{
return 'Error: Uploaded file not an image';
}
PHP has to be compiled with the --enable-exif tag for this to work.
see http://us3.php.net/manual/en/function.exif-imagetype.php for more details
-Rusty
---------------------------------
Looking for last minute shopping deals? Find them fast with Yahoo! Search.
More information about the UPHPU
mailing list