《PHP應用:php通過文件頭判斷格式的方法》要點:
本文介紹了PHP應用:php通過文件頭判斷格式的方法,希望對您有用。如果有疑問,可以聯系我們。
PHP實戰本文實例講述了php通過文件頭判斷格式的方法.分享給大家供大家參考,具體如下:
PHP實戰
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;
}
}
PHP實戰補充:小編在這里推薦一款本站的php格式化美化的排版工具幫助大家在以后的PHP程序設計中進行代碼排版:
PHP實戰php代碼在線格式化美化工具:
PHP實戰http://tools.jb51.net/code/phpformat
PHP實戰另外,由于php屬于C語言風格,因此下面這款工具同樣可以實現php代碼的格式化:
PHP實戰C語言風格/HTML/CSS/json代碼格式化美化工具:
http://tools.jb51.net/code/ccode_html_css_json
PHP實戰更多關于PHP相關內容感興趣的讀者可查看本站專題:《PHP數學運算技巧總結》、《php操作office文檔技巧總結(包括word,excel,access,ppt)》、《PHP數組(Array)操作技巧大全》、《php排序算法總結》、《PHP常用遍歷算法與技巧總結》、《PHP數據結構與算法教程》、《php程序設計算法總結》、《php正則表達式用法總結》、《PHP運算與運算符用法總結》、《php字符串(string)用法總結》及《php常見數據庫操作技巧匯總》
PHP實戰希望本文所述對大家PHP程序設計有所幫助.
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/6306.html