HealthLinks is your destination for reliable, understandable, and credible health information and expert advice that always keeps why you came to us in mind.

PHP File Upload Types

104 216

    Image Files

    • Generally, image file types, also called graphic file types, will start with "image/", followed by the image type code. The most common image types handled in PHP web application are "image/gif," which is a GIF file, "image/jpg" or "image/jpeg", which is a JPEG file and "image/png," which is a PNG file.

      The file type reported in PHP's $_FILES array is based on information provided by the user's web browser. So it can't be explicitly trusted. Luckily, PHP provides functions for manipulating and getting information about image files. When someone uploads an image file, consider using getimagesize() or exif_imagetype() to further analyze it. The GD, Image, imagick and exif functions can also be used to process user-uploaded image files for more robust applications.

    Text Files

    • Text files are any kind of file that just contains text. The file type name starts with "text/." If your PHP application is not meant to interpret any code or markup that's found inside files, then you can probably ignore the letters after the "/."

      Examples of text files whose content can be interpreted include "text/html," which is an HTML file or web page, "text/xml," which is an XML data file and "text/csv," which is a comma-separated-value data file. PHP applications that accept this upload type often use the string parsing functions to interpret the contents of the file. The XML functions are also particularly useful for interpreting text/xml files.

      An unformatted text file that isn't meant to be interpreted for code or markup is called "text/plain."

    Application Files

    • There is a very broad class of file types that starts with "application/." These are files that go with various applications, such as Microsoft Word or Adobe Photoshop. As such, there are hundreds of recognized application file types. Your PHP application should only respond to uploaded application files if it is explicitly written to handle one or more such files. For example, your application may be written to take Microsoft Excel files and extract the data from them. In that case, you would refer to Microsoft's developer documentation to find the MIME type for Excel files.

    Multipart Files

    • It is unlikely that your application will receive a file whose file type name starts with "multipart/." This kind of MIME type is used inside emails. If an uploaded file's type starts with "multipart/," it is best for your application to ignore it unless you have specific knowledge of what you are doing.

    Other Types

    • There are several other types that may come up such as "video/", "audio/" and others. PHP has no specific, out-of-the-box way of handling such files. If you wish to write an application that uses them, look for documentation on the kinds of files you wish to handle.

Source...

Leave A Reply

Your email address will not be published.