-
-
/**
- * Detect upload file type
- * 检测上传文件的excel文件类型
- * @param array $file
- * @return bool $flag
- * @site bbs.it-home.org
- */
- private function detectUploadFileMIME($file) {
- // 1.through the file extension judgement 03 or 07
- $flag = 0;
- $file_array = explode ( ".", $file ["name"] );
- $file_extension = strtolower ( array_pop ( $file_array ) );
-
- // 2.through the binary content to detect the file
- switch ($file_extension) {
- case "xls" :
- // 2003 excel
- $fh = fopen ( $file ["tmp_name"], "rb" );
- $bin = fread ( $fh, 8 );
- fclose ( $fh );
- $strinfo = @unpack ( "C8chars", $bin );
- $typecode = "";
- foreach ( $strinfo as $num ) {
- $typecode .= dechex ( $num );
- }
- if ($typecode == "d0cf11e0a1b11ae1") {
- $flag = 1;
- }
- break;
- case "xlsx" :
- // 2007 excel
- $fh = fopen ( $file ["tmp_name"], "rb" );
- $bin = fread ( $fh, 4 );
- fclose ( $fh );
- $strinfo = @unpack ( "C4chars", $bin );
- $typecode = "";
- foreach ( $strinfo as $num ) {
- $typecode .= dechex ( $num );
- }
- echo $typecode;
- if ($typecode == "504b34") {
- $flag = 1;
- }
- break;
- }
-
- // 3.return the flag
- return $flag;
- }
复制代码
|
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31