Page 1 of 1

How do I use $File_type

Posted: Sat Jun 12, 2004 5:38 am
by andylyon87
Hi guys
does anyone know how to restrict the type of file on file uploads, would I need to use an pattern matcher or is it a hidden input. I am wanting to just allow image uploads (jpg, bmp, tiff, gif extensions).

help much appreciated

Posted: Sat Jun 12, 2004 8:01 am
by launchcode
You could use $_FILES['userfile']['type'] after the file has uploaded and compare the mime type with your allowed list, however not all browsers will send this. If you want to check for images that PHP supports you could run getimagesize() on the uploaded file - then it'll tell you exactly what it is based on the file data. Another way would be to check the extension of the file (i.e. substr the last part of the filename) - but this won't be as accurate as getimage is.

Posted: Sat Jun 12, 2004 10:25 pm
by maqmus
You can't be sure before the file is uploaded, but you could use javascript to check extension and the use exif_imagetype().