Php uses the file header to determine the format,

Source: Internet
Author: User

Php uses the file header to determine the format,

This article describes how php uses the file header to determine the format. We will share this with you for your reference. The details are as follows:

function judgeFile($file,$form){if(!empty($file) && !empty($form)){$filehead = fopen($file,'r');$bin = fread($filehead, 2);fclose($filehead);$data = unpack('C2chars', $bin);$type_code = intval($data['chars1'].$data['chars2']);switch ($type_code) {case 7790: $fileType = 'exe';break;  case 7784: $fileType = 'midi';break;  case 8075: $fileType = 'zip';break;  case 8297: $fileType = 'rar';break;  case 255216: $fileType = 'jpg';break;  case 7173: $fileType = 'gif';break;  case 6677: $fileType = 'bmp';break;  case 13780: $fileType = 'png';break;  default: $fileType = 'unknown';break;}if(!is_array($form)){if($fileType==$form){return true;}else{return false;}}else{if(in_array($file, $form)){return true;}else{return FALSE;}}}else{return false;}}

Supplement: The editor recommends a php formatting and formatting typographical tool on this site to help you typeset code in future PHP programming:

Php code online formatting and beautification tools:

Http://tools.jb51.net/code/phpformat

In addition, because php belongs to the C language style, the following tool can also format php code:

C language style/HTML/CSS/json code formatting and beautification tools:
Http://tools.jb51.net/code/ccode_html_css_json

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.