Page 1 of 1

Restrict File Types for Upload

Posted: Fri Apr 09, 2010 8:34 pm
by devarishi
How to restrcit selections of files for upload - client / browser side?

The attribute accept="image/jpeg" doesn't seem to have any effect in file tag of HTML.

Note: I am using HTML and PHP only and am not familiar with Ajax or any other such tools. I want users to be able to browse and select only image (.jpg) files.

Re: Restrict File Types for Upload

Posted: Sun Apr 11, 2010 5:29 pm
by yacahuma
http://www.webcheatsheet.com/PHP/file_upload.php


you restrict using the type property

$_FILES["uploaded_file"]["type"]

Re: Restrict File Types for Upload

Posted: Sun Apr 11, 2010 7:23 pm
by requinix
I don't know of any browser that honors the accept property.

Also, using $_FILES[...]["type"] is very risky. It's supplied by the browser which means a malicious user could fake it.
Figure out the file type yourself. For images you can use getimagesize; for others you can make something yourself or use the fileinfo extension.