Php exif_imagetype():无法打开流:第30行C中没有此类文件或目录

Php exif_imagetype():无法打开流:第30行C中没有此类文件或目录,php,image,upload,Php,Image,Upload,好吧,我试着上传一张照片到一个文件夹。当只上传一张照片时,它可以工作,但当我尝试上传第二张照片时,它不允许我上传,并返回此错误: Warning: exif_imagetype(gallery/inerieur abu 3.jpg): failed to open stream: No such file or directory in C:\xampp\htdocs\campi\admin\upload-gallery.php on line 30 Warning: unlink(galle

好吧,我试着上传一张照片到一个文件夹。当只上传一张照片时,它可以工作,但当我尝试上传第二张照片时,它不允许我上传,并返回此错误:

Warning: exif_imagetype(gallery/inerieur abu 3.jpg): failed to open stream: No such file or directory in C:\xampp\htdocs\campi\admin\upload-gallery.php on line 30

Warning: unlink(gallery/inerieur abu 3.jpg): No such file or directory in C:\xampp\htdocs\campi\admin\upload-gallery.php on line 34
这是我的代码,我使用一个函数来检查图像并将其上传到文件夹中

<?php
error_reporting(-1);
if (isset($_POST['gallery-upload'])) {
    $hostname='localhost';
    $username='root';
    $password='';
    $filter = $_POST['filter'];

    function uploadImage($img_ff, $dst_path, $dst_img){

        //Get variables for the function.
                //complete path of the destination image.
        $dst_cpl = $dst_path . basename($dst_img);
                //name without extension of the destination image.
        $dst_name = preg_replace('/\.[^.]*$/', '', $dst_img);
                //extension of the destination image without a "." (dot).
        $dst_ext = strtolower(end(explode(".", $dst_img)));

    //Check if destination image already exists, if so, the image will get an extra number added.
        while(file_exists($dst_cpl) == true){
            $i = $i+1;
            $dst_img = $dst_name . $i . '.' . $dst_ext;
            $dst_cpl = $dst_path . basename($dst_img);
        }

            //upload the file and move it to the specified folder.
        move_uploaded_file($_FILES[$img_ff]['tmp_name'], $dst_cpl);

            //get type of image.
        $dst_type = exif_imagetype($dst_cpl);

            //Checking extension and imagetype of the destination image and delete if it is wrong.
        if(( (($dst_ext =="jpg") && ($dst_type =="2")) || (($dst_ext =="jpeg") && ($dst_type =="2")) || (($dst_ext =="gif") && ($dst_type =="1")) || (($dst_ext =="png") && ($dst_type =="3") )) == false){
            unlink($dst_cpl);
            die('<p>The file "'. $dst_img . '" with the extension "' . $dst_ext . '" and the imagetype "' . $dst_type . '" is not a valid image. Please upload an image with the extension JPG, JPEG, PNG or GIF and has a valid image filetype.</p>');
        }
    }

    if($_SERVER['REQUEST_METHOD'] == 'POST'){

            //Variables needed for the function.
        $img_ff = 'image'; // Form name of the image
        $dst_img = strtolower($_FILES[$img_ff]['name']); // This name will be given to the image. (in this case: lowercased original image name uploaded by user).
        $dst_path = 'gallery/'; // The path where the image will be moved to.

        uploadImage($img_ff, $dst_path, $dst_img);
            try {

                $dbh = new PDO("mysql:host=$hostname;dbname=dddoecje_campu",$username,$password);
                $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
                $stmt = $dbh->prepare("INSERT INTO `gallery`(`id`, `image`, `filter`) VALUES ('',:image,:filter)");
                $stmt->bindParam(':filter', $filter);
                $stmt->bindParam(':image', $dst_img, PDO::PARAM_LOB);
                $dbh->errorInfo();
                $stmt->execute();
                // use exec() because no results are returned
                header("Location: index.php?lang=" . $lang);

            }
            catch(PDOException $e)
            {
                echo $stmt . "<br>" . $e->getMessage();
            }
    }



    $dbh = null;
}
?>
根据
exif\u imagetype()
需要针对
temp
文件名而不是文件名运行

$\u文件['userfile']['tmp\u name']
不同的是
$\u文件['userfile']['name']

就像代码中发生的事情一样

在附近添加:

$dst_img=strtolower($_文件[$img_ff]['name'])

$dst_tmp_img=strtolower($_文件[$img_ff]['tmp_名称])

并将功能更改为:

函数上载映像($img_ff、$dst_path、$dst_img
,$dst_tmp_img

然后将
$dst_type
值更改为等于:

$dst_类型=exif_图像类型(
$dst_tmp_img

然后,您的代码将更可靠地工作。

根据
exif\u imagetype()
需要针对
temp
文件名而不是文件名运行

$\u文件['userfile']['tmp\u name']
不同的是
$\u文件['userfile']['name']

就像代码中发生的事情一样

在附近添加:

$dst_img=strtolower($_文件[$img_ff]['name'])

$dst_tmp_img=strtolower($_文件[$img_ff]['tmp_名称])

并将功能更改为:

函数上载映像($img_ff、$dst_path、$dst_img
,$dst_tmp_img

然后将
$dst_type
值更改为等于:

$dst_类型=exif_图像类型(
$dst_tmp_img

这样,您就可以确保代码工作更可靠