通过接收文件流来上传文件,请问如何准确判断文件后缀
这是网上看到的通过识别文件信息来区分
<?php
$data = file_get_contents('php://input');
$strInfo = @unpack("C2chars", substr($data,0,2));
$typeCode = intval($strInfo["chars1"].$strInfo["chars2"]);
$fileTypes = array(
7790 => "exe",
7784 => "midi",
8075 => "zip",
8297 => "rar",
225216 => "jpg",
7173 => "gif",
6677 => "bmp",
13780 => "png",
);
$fileType = isset($fileTypes[$typeCode]) ? $fileTypes[$typeCode] : "unknown";
echo "type : {$fileType} code : {$fileType}";
?>
推荐文章: