Page 1 of 1

upload files

Posted: Sat May 05, 2007 7:31 pm
by kippy
What is the best way to define a set of file types for uploads?

Posted: Sat May 05, 2007 7:40 pm
by Weirdan
The best? Db table or config array - both will work well if handled properly.

Posted: Sat May 05, 2007 7:43 pm
by kippy
Thanks for the quick response....

So basically I can set up an array with extensions and compare it to the $_FILE$[$filename]['type'] ?

Posted: Sat May 05, 2007 7:48 pm
by Weirdan
Comparing file extension to type makes little sense because of:
PHP manual wrote: $_FILES['userfile']['type']

The mime type of the file, if the browser provided this information. An example would be "image/gif". This mime type is however not checked on the PHP side and therefore don't take its value for granted.

Posted: Sat May 05, 2007 7:50 pm
by kippy
I see...I guess I am confused then on how I will use the array?

Posted: Sat May 05, 2007 10:51 pm
by Ambush Commander
The config array will define what the allowed types are. In order to get the type from the file, however, you will have to sniff it using mime magic (if you have fileinfo, use finfo_file(), you can also try mime_content_type())