上传文件,只判断后缀,貌似还不是很严谨;
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 |
/** * 判断文件是否合法 * @param $files * @param $arrCode * @return number|boolean */function
checkFileType($files, $arrCode
= array()){ $file
= @fopen($files[‘tmp_name‘], "rb"); $bin
= @fread($file, 2); fclose($file); $str
= @unpack(‘C2chars‘, $bin); $code
= intval($str[‘chars1‘].$str[‘chars2‘]); if(! is_array($arrCode)) return
$code; return
array_key_exists($code, $arrCode);}//Demo $arrCode
= array( 6063 => ‘php‘, 208207 => ‘xls‘,);//如只允许上传php,和xls文件$result
= checkFileType($_FILES[‘file‘], $arrCode); |
原文:http://www.cnblogs.com/lifelog/p/3517450.html