Page 1 of 1

finding a file type

Posted: Thu Dec 07, 2006 8:35 am
by hame22
Hi I am allowing users to upload files to my site.

However I would like to restrict them to just PDF, word files and powerpoint presentations.

Is there a function like getimagesize to allow this?

File types

Posted: Thu Dec 07, 2006 8:45 am
by timclaason
I would use substr().

For instance:

Code: Select all

if(substr($_FILES['theimage']['name'], -4) != ".doc") {
   print("Invalid File Type");
}
or preg_match() or some other string function.

Posted: Thu Dec 07, 2006 8:57 am
by volka
And if I upload an vbscript that I named funny.gif (or funny.doc)? This really worked in IE some time ago and the script got executed. Don't rely on a simple file suffix.
Take a look at http://de2.php.net/ref.mime-magic