Share to everyone php to judge upload file types of methods, we learn together.
/** * Read the first few bytes of the file to determine the file type * @return String/function Checktitle ($filename) {$file =fopen ($fi
Lename, "RB"); $bin =fread ($file, 2);
Read Only 2 bytes fclose ($file);
$strInfo = @unpack ("C2chars", $bin);
$typeCode =intval ($strInfo [' chars1 ']. $strInfo [' chars2 ']);
$fileType = ';
Switch ($typeCode) {case 7790: $fileType = ' exe ';
Break
Case 7784: $fileType = ' midi ';
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 '. $typeCode;
Break
//fix if ($strInfo [' chars1 ']== '-1 ' && $strInfo [' chars2 ']== ' -40 ') {return ' JPG ';
} if ($strInfo [' chars1 ']== ' -119 ' && $strInfo [' chars2 ']== ') {return ' PNG ';
return $fileType; }
Hopefully this article will help you learn about PHP programming.