抱歉,只支持JPG, JPEG, PNG &GIF文件是允许的


Sorry, only JPG, JPEG, PNG & GIF files are allowed

我正在尝试创建一个脚本,允许用户向我们提供信息并上传3张图像到数据库,以显示他们所面临的问题的证据。

我使用了一个我在网上找到的脚本,并修改了它来处理我的表单。图片没有被上传,因为我得到错误'对不起,只有JPG, JPEG, PNG &;GIF文件是允许的。,如下面的代码所示。我上传的图片肯定是。jpg,所以我不明白为什么会发生这种情况?

<?php
    if(isset($_POST['submitForm'])) {
        $firstname = $_POST['firstname'];
        $lastname = $_POST['lastname'];
        $email = $_POST['email'];
        $organisation = $_POST['organisation'];
        $question_1 = $_POST['question1'];
        $question_2 = $_POST['question2'];
        $question_3 = $_POST['question3'];
        $question_4 = $_POST['question4'];
        $question_5 = $_POST['question5'];
        $image_1 = $_POST['fileToUpload1'];
        $image_2 = $_POST['fileToUpload2'];
        $image_3 = $_POST['fileToUpload3'];
        $message = $_POST['message'];
        $target_dir = "/var/www/vhosts/system/removed.co.uk/etc/contact-facility/uploads/";
        $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
        $uploadOk = 1;
        $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
        $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
        if($check !== false) {
            $uploadOk = 1;
        }
        else {
            $uploadOk = 0;
        }
        if (file_exists($target_file)) {
            $uploadOk = 0;
        }
        if ($_FILES["fileToUpload"]["size"] > 500000) {
            echo "Sorry, your file is too large.";
            $uploadOk = 0;
        }
        if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) {
            echo "Sorry, only JPG, JPEG, PNG &amp; GIF files are allowed.";
            $uploadOk = 0;
        }
        $servername = "localhost";
        $username = "removed";
        $password = "removed";
        $dbname = "removed";
        try {
            $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
            $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $sql = "INSERT INTO contact_facility (first_name, last_name, email_address, hospital_trust, question_1, question_2, question_3, question_4, question_5, image_1, image_2, image_3, message) VALUES ('$firstname', '$lastname', '$email', '$organisation', '$question_1', '$question_2', '$question_3', '$question_4', '$question_5', '$image_1', '$image_2', '$image_3', '$message')";
            $conn->exec($sql);
            $success = "<p style='color: green;'>Thank you for contacting REMOVED.<br /><br />We have received your Contact Enquiry and will contact you within 24-48 hours with information regarding your request.</p>";
        }
        catch(PDOException $e) {
            echo $sql . "<br />" . $e->getMessage();
        }
        $conn = null;
    }
?>

我不明白为什么这些图像是A:不上传和B:在文件扩展名上显示错误,而我上传的图像显然是。jpg。

我哪里做错了,你会如何解决这个问题?

$target_dir = "uploads/";
        $target_inner = "uploads/".$email;
        $img_inner = mkdir($target_inner);
        if($img_inner=='1'){
            $target_file = $target_inner ."/" . basename($_FILES["fileToUpload"]["name"]);
            $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
        }
         $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
         $uploadOk = 1;
        // Check if $uploadOk is set to 0 by an error
        if ($uploadOk == 0) {
            echo "error in uploading image";
        // if everything is ok, try to upload file
        }
        // Check if file already exists
        if (file_exists($target_file)) {
            echo "Sorry, file already exists.";
            $uploadOk = 0;          }
        // Check file size
        if ($_FILES["fileToUpload"]["size"] > 100000) {
           echo "Sorry, your file is too large.";
           $uploadOk = 0; 
    }
        // Allow certain file formats
        if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" ) {
            echo "Sorry, only jpg, jpeg and png files are allowed.";
            $uploadOk = 0;
        }
        else
         {
            if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
                echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
            }
             else {
                echo "Sorry, there was an error uploading your file.";
            }
                if($uploadOk==1)
                {
                    $sql = "INSERT INTO(your query)
// I am sure it will work