Php mime processing problems

Source: Internet
Author: User
According to my personal experience, when processing File Uploads in php, the following methods can be often used to determine the file type through the filename suffix, which is not secure and can be easily determined by mime, some types of files can be identified by the header byte by modifying the file suffix... based on my personal experience, when processing File Uploads in php, you can often use the following methods to determine the file type:

  1. It is difficult to cheat by filename suffix
  2. It is determined by mime that some types of files can be spoofed to the server by modifying the file suffix.
  3. The file type is determined by the header bytes, but the judgment range is limited. For example, a new document such as docx/xlsx is actually a zip package when the header information is used for judgment.

Is there any other way to obtain the file type more reasonably and securely?

Reply content:

Based on my personal experience, when processing File Uploads in php, you can often use the following methods to determine the file type:

  1. It is difficult to cheat by filename suffix
  2. It is determined by mime that some types of files can be spoofed to the server by modifying the file suffix.
  3. The file type is determined by the header bytes, but the judgment range is limited. For example, a new document such as docx/xlsx is actually a zip package when the header information is used for judgment.

Is there any other way to obtain the file type more reasonably and securely?

In my opinion, the subject needs to ensure the security of file upload.
First, you must set the file type and size hard. In addition, I personally thinkmimeThe type determination is safe. If the subject is still insecure, you can read the file header to determine the actual type.
The method can be referred to in this case:

PHP determines the actual type of a file and its application example by reading two bytes in the file header

When I see the content in the question of the subject, I think the three methods mentioned by the subject will increase the security level in sequence. If these three methods are implemented layer by layer, I think the security should be guaranteed.

Determine the header first. If the image is uploaded to gd, use openoffice if the document is used.
Fake ones will also turn you into real ones.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.