Page 1 of 1
PHP and image formats
Posted: Mon Nov 08, 2004 9:34 am
by rtlm
Hi all,
I have a php script which users can upload images to. Are there any functions I can use to ensure that the users only upload images with certain extentions?
Posted: Mon Nov 08, 2004 9:42 am
by pickle
When you upload a file via HTTP, there is an element in the $_FILES array that stores the MIME type of the upload.
Posted: Mon Nov 08, 2004 9:48 am
by phpScott
see also [php_man]getimagesize[/php_man]().
Posted: Mon Nov 08, 2004 9:48 am
by Getran
You could also do a check before uploading to check the type of file, maybe something like:
Code: Select all
if ($filevar != "image/gif") {
echo "File Type Illegal";
} else {
// Upload
}
I used the image/gif thing once before but i don't remember how i got it working, i'm sorry about that but hopefully this will give you an idea...
Posted: Mon Nov 08, 2004 9:49 am
by josh
Yeah, the 'type' thing outputs the mime type like:
image/jpg
image/gif etc...
I have however experienced problems with this for instance when a user uploads some files the type == NULL for some reason and I am forced to trust the file extension, but some one could just change the file extension and upload something.exe.jpg..... Why does the type come out to NULL? Is there any other ways to check the encoding of the file?
Posted: Mon Nov 08, 2004 9:49 am
by phpScott
phpScott wrote:see also [php_man]getimagesize[/php_man]().
see also
[php_man]mime_content_type[/php_man]()