Question

I'm trying to find a reference that shows what the different names of the "TYPES" are like $_FILES["file"]["type"] == "image/gif" but I'm looking for the csv, ms excel, mac numbers, ms word, etc.

I can't find anything on php.net or google. I'm most likely calling it the wrong thing anyway.

What is it called that I should be looking for?

Was it helpful?

Solution

This is actually explained in the PHP Manual.

From http://php.net/manual/en/features.file-upload.post-method.php (emphasis mine)

$_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.

So the term you are looking for is MIME TYPE. Putting that into Google will likely make you end up at Wikipedia's https://en.wikipedia.org/wiki/Internet_media_type

An Internet media type[1] is a two-part identifier for file formats on the Internet. The identifiers were originally defined in RFC 2046 for use in email sent through SMTP, but their use has expanded to other protocols such as HTTP, RTP and SIP. These types were called MIME types, and are sometimes referred to as Content-types, after the name of a header in several protocols whose value is such a type.

The article also states

IANA manages the official registry of media types

Following the link will lead you to

and that contains the list you are looking for. Note that looking at that list is mostly pointless unless you want to find out what an official mimetype for a particular file format is.

On a side note: if you want to validate/detect the mime type of a file, check the code I have provided in

OTHER TIPS

You're looking for MIME types. Note, however, that you should not trust $_FILES['...']['type']. Instead, you should analyse the file contents themselves to make sure they are the proper format.

Found the following list on a forum, seems complete enough to post it here

'hqx'   =>  'application/mac-binhex40'
'cpt'   =>  'application/mac-compactpro'
'csv'   =>  'text/x-comma-separated-values', 'application/vnd.ms-excel'
'bin'   =>  'application/macbinary'
'dms'   =>  'application/octet-stream'
'lha'   =>  'application/octet-stream'
'lzh'   =>  'application/octet-stream'
'exe'   =>  'application/octet-stream'
'class' =>  'application/octet-stream'
'psd'   =>  'application/x-photoshop'
'so'    =>  'application/octet-stream'
'sea'   =>  'application/octet-stream'
'dll'   =>  'application/octet-stream'
'oda'   =>  'application/oda'
'pdf'   =>  'application/pdf', 'application/x-download'
'ai'    =>  'application/postscript'
'eps'   =>  'application/postscript'
'ps'    =>  'application/postscript'
'smi'   =>  'application/smil'
'smil'  =>  'application/smil'
'mif'   =>  'application/vnd.mif'
'xls'   =>  'application/excel', 'application/vnd.ms-excel'
'ppt'   =>  'application/powerpoint'
'wbxml' =>  'application/wbxml'
'wmlc'  =>  'application/wmlc'
'dcr'   =>  'application/x-director'
'dir'   =>  'application/x-director'
'dxr'   =>  'application/x-director'
'dvi'   =>  'application/x-dvi'
'gtar'  =>  'application/x-gtar'
'gz'    =>  'application/x-gzip'
'php'   =>  'application/x-httpd-php'
'php4'  =>  'application/x-httpd-php'
'php3'  =>  'application/x-httpd-php'
'phtml' =>  'application/x-httpd-php'
'phps'  =>  'application/x-httpd-php-source'
'js'    =>  'application/x-javascript'
'swf'   =>  'application/x-shockwave-flash'
'sit'   =>  'application/x-stuffit'
'tar'   =>  'application/x-tar'
'tgz'   =>  'application/x-tar'
'xhtml' =>  'application/xhtml+xml'
'xht'   =>  'application/xhtml+xml'
'zip'   => 'application/x-zip', 'application/zip', 'application/x-zip-compressed'
'mid'   =>  'audio/midi'
'midi'  =>  'audio/midi'
'mpga'  =>  'audio/mpeg'
'mp2'   =>  'audio/mpeg'
'mp3'   =>  'audio/mpeg'
'aif'   =>  'audio/x-aiff'
'aiff'  =>  'audio/x-aiff'
'aifc'  =>  'audio/x-aiff'
'ram'   =>  'audio/x-pn-realaudio'
'rm'    =>  'audio/x-pn-realaudio'
'rpm'   =>  'audio/x-pn-realaudio-plugin'
'ra'    =>  'audio/x-realaudio'
'rv'    =>  'video/vnd.rn-realvideo'
'wav'   =>  'audio/x-wav'
'bmp'   =>  'image/bmp'
'gif'   =>  'image/gif'
'jpeg'  =>  'image/jpeg', 'image/pjpeg'
'jpg'   =>  'image/jpeg', 'image/pjpeg'
'jpe'   =>  'image/jpeg', 'image/pjpeg'
'png'   =>  'image/png',  'image/x-png'
'tiff'  =>  'image/tiff'
'tif'   =>  'image/tiff'
'css'   =>  'text/css'
'html'  =>  'text/html'
'htm'   =>  'text/html'
'shtml' =>  'text/html'
'txt'   =>  'text/plain'
'text'  =>  'text/plain'
'log'   =>  'text/plain', 'text/x-log'
'rtx'   =>  'text/richtext'
'rtf'   =>  'text/rtf'
'xml'   =>  'text/xml'
'xsl'   =>  'text/xml'
'mpeg'  =>  'video/mpeg'
'mpg'   =>  'video/mpeg'
'mpe'   =>  'video/mpeg'
'qt'    =>  'video/quicktime'
'mov'   =>  'video/quicktime'
'avi'   =>  'video/x-msvideo'
'movie' =>  'video/x-sgi-movie'
'doc'   =>  'application/msword'
'word'  =>  'application/msword', 'application/octet-stream'
'xl'    =>  'application/excel'
'eml'   =>  'message/rfc822'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top