This article illustrates how PHP uses the file header to determine the format. Share to everyone for your reference, specific 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 ';
Case 7784: $fileType = ' midi ';
Case 8075: $fileType = ' zip ';
Case 8297: $fileType = ' rar ';
Case 255216: $fileType = ' jpg ';
Case 7173: $fileType = ' gif ';
Case 6677: $fileType = ' bmp ';
Case 13780: $fileType = ' png ';
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;
}
Add: small knitting here recommend a site for the layout of the PHP format landscaping tools to help you in the future of PHP programming code layout:
PHP code online format Landscaping tools:
Http://tools.jb51.net/code/phpformat
In addition, because PHP belongs to the C language style, the following tool can also be used to format PHP code:
C Language Style/html/css/json code formatting landscaping Tools:
Http://tools.jb51.net/code/ccode_html_css_json
More interested in PHP related content readers can view the site topics: "PHP Math Arithmetic Skills summary", "PHP operation Office Document Skills Summary (including word,excel,access,ppt)", "PHP Array" operation Skills Encyclopedia, " Summary of the PHP sorting algorithm, "PHP commonly used traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP string (String) Usage summary" and " A summary of common PHP database operations tips
I hope this article will help you with the PHP program design.