Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does php get the file type without a suffix?

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the "php does not get the file type through the suffix", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "php does not get the file type through the suffix" bar!

The method of getting the file type: 1, use the "$_ FILES ['uploadfile'] [' type']" statement; 2, use the "finfo_file (finfo_open (FILEINFO_MIME), file path)" statement; 3, judge by reading the first six bytes of the file.

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

Php gets the file type (without suffixes)

Method 1:$_FILES

If the file is uploaded by php, you can use $_ FILES ['uploadfile'] [' type'] to get the file type, but it also has the same problem as pathinfo, this method can only determine the file type based on the file suffix.

Method 2:php Fileinfo to get the file MIME type (finfo_open)

Code example:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report