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
How do I use $File_type
Moderator: General Moderators
-
andylyon87
- Forum Contributor
- Posts: 168
- Joined: Sat Jan 31, 2004 5:31 am
- Location: Dundee
- launchcode
- Forum Contributor
- Posts: 401
- Joined: Tue May 11, 2004 7:32 pm
- Location: UK
- Contact:
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.
You can't be sure before the file is uploaded, but you could use javascript to check extension and the use exif_imagetype().