Search code examples
phpfile-uploadfile-type

What are the file types you can upload via PHP?


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?


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