PHP uses the finfo_file () function to detect the implementation of the uploaded image type,

Source: Internet
Author: User

PHP uses the finfo_file () function to detect the implementation of the uploaded image type,

This example describes how PHP uses the finfo_file () function to detect the uploaded image type. We will share this with you for your reference. The details are as follows:

In input and output, file interaction is essential, such as file upload. Here we will solve a small problem, that is, how to determine the file type uploaded by the user.

For exampleApplication Scenario: The segment is forcibly modified to nowamagic.png, so that the program cannot cut this type of image, and the cut fails. In this case, it is necessary to check the file, and it cannot be determined only by the suffix.

PHP certainly comes with some functions to implement such a common requirement. This function isfinfo_file.

finfo_file

(PHP> = 5.3.0, PECL fileinfo> = 0.1.0)

Finfo_file -- finfo: file-Return information about a file, This function is used to get information about a file.

The function is very simple. You can see the official document clearly. Here is an example of how to upload an image and determine its type:

<Html> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "> 

Note:Yes,The finfo_file function requires PHP version> = 5.3.0. If it is lower than 5.3, you need to remove the semicolon before extension = php_fileinfo.dll in php. ini to enable it..

Of course, there are many ways to detect file types, which will be discussed later.

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.