Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Getimagesize返回数组而不是布尔值_Php - Fatal编程技术网

Php Getimagesize返回数组而不是布尔值

Php Getimagesize返回数组而不是布尔值,php,Php,我在网站上有图片上传表单,允许用户上传他们的图片。现在我正在尽可能地保护它。使用php_图像_魔术师 这就是我在代码中检查图像的地方 for ($i = 0; $i < count($_FILES["user_files"]["name"]); $i++) { if ($_FILES["user_files"]["name"][$i] <> "") { $image_mime = strtolower(image_type_to_mime_type(exif_im

我在网站上有图片上传表单,允许用户上传他们的图片。现在我正在尽可能地保护它。使用php_图像_魔术师

这就是我在代码中检查图像的地方

for ($i = 0; $i < count($_FILES["user_files"]["name"]); $i++) {
  if ($_FILES["user_files"]["name"][$i] <> "") {

    $image_mime = strtolower(image_type_to_mime_type(exif_imagetype($_FILES["user_files"]["tmp_name"][$i])));

$tempFile =  $_FILES["user_files"]["tmp_name"][$i];
$getImgSize = getimagesize($tempFile);   

    // if valid image type then upload
    if (in_array($image_mime, $valid_image_check, $getImgSize)) {
        ....
        // upload image
    }
var_dump$_FILES[user_FILES][tmp_name][$i]返回string14/tmp/phpkBZOW3


表单接受多个图像,所以这就是为什么它适用于那里和[$i]。这里有什么问题?

你可以这样试试。但正如@Paul所说的,检查一下


我不认为在传递论点时有正确的顺序,或者它有?第一个参数检查图像mime,第二个参数检查jpeg/png/bmp/etc,第三个参数检查getimagesize..谢谢。这项工作做得很好,我现在明白我的错误在哪里了。
$tempFile =  $_FILES["user_files"]["tmp_name"][$i];
$getImgSize = getimagesize($tempFile); 
for ($i = 0; $i < count($_FILES["user_files"]["name"]); $i++) {
  if ($_FILES["user_files"]["name"][$i] <> "") {
    $image_mime = strtolower(image_type_to_mime_type(exif_imagetype($_FILES["user_files"]["tmp_name"][$i])));

    $getImageFile = getimagesize($_FILES["user_files"]["tmp_name"][$i]);

    if(!empty($getImageFile)){
        echo 'Please ensure you are uploading an image.';
        exit;
    }    

    // if valid image type then upload
    if (in_array($image_mime, $valid_image_check)) {