检查php中的文件类型上载
这是怎么回事检查php中的文件类型上载,php,Php,这是怎么回事 if($_FILES['SelectedFile']['type'] != 'image/png' or 'image/jpg' or 'image/gif' || 'image/jpeg'){ outputJSON('Unsupported filetype uploaded.'); } 我的文件是something.PNG,它不会传递上面的if语句。我将代码改为'image/PNG',因为它可能是大写字母,但不是大写字母。我想知道为什么 编辑 var_dump($_F
if($_FILES['SelectedFile']['type'] != 'image/png' or 'image/jpg' or 'image/gif' || 'image/jpeg'){
outputJSON('Unsupported filetype uploaded.');
}
我的文件是something.PNG,它不会传递上面的if语句。我将代码改为'image/PNG'
,因为它可能是大写字母,但不是大写字母。我想知道为什么
编辑
var_dump($_FILES['SelectedFile']['type'])
array(5) { ["name"]=> string(11) "Capture.png" ["type"]=> string(9) "image/png" ["tmp_name"]=> string(24) "C:\xampp\tmp\phpE58A.tmp" ["error"]=> int(0) ["size"]=> int(7818) }
试试这个:
$haystack = array("image/png","image/jpg","image/jpeg","image/gif");
if(!in_array(strtolower($_FILES['SelectedFile']['type']), $haystack){
outputJSON('Unsupported filetype uploaded.');
}
您的表达式不正确,应该是:
$type = $_FILES['SelectedFile']['type'];
if ($type != 'image/png' && $type != 'image/jpg' && $type != 'image/gif' && $type != 'image/jpeg') {
outputJSON('Unsupported filetype/uploaded');
}
或者不像在自然语言中那样在编程语言中分布。什么是var\u dump($\u FILES['SelectedFile'])
show?@johncode[array(5){[“name”]=>string(11)“Capture.png”[“type”]=>string(9)“image/png”[“tmp\u name”]=>string(24)“C:\xampp\tmp\phpE58A.tmp”[“error”]=>int(0)[“size”=>int(7818) }