ไฟล์ PHP ไม่ได้อัปโหลด

ฉันมีแบบฟอร์มสำหรับอัพโหลดรูปภาพ อย่างไรก็ตาม ด้วยเหตุผลบางอย่าง ฉันไม่สามารถอัปโหลดภาพได้ ฉันได้อัปเดตสิทธิ์ของไฟล์แล้ว (สิทธิ์ 777 สิทธิ์) แต่ยังคงไม่สามารถอัปโหลดไฟล์ได้ ดูเหมือนว่าแบบฟอร์มจะใช้งานได้เนื่องจากข้อความ (ไม่รวมอยู่ในแบบฟอร์มกำลังอัปเดต)

<form action="manage_content.php?project=5" method="post" enctype="multipart/form-data">
    <div class="width">
        <p>Project Image: <br>
        <input type="file" name="image_file" id="file" class="inputfile" />
        <label for="file">Choose a file</label>
        </p>
    </div>
    <input type="submit" name="update_project" value="Update Current Project">    
</form>

การประมวลผลแบบฟอร์ม PHP

if (isset($_POST['update_project'])) {
    $required_fields = array("project_name", "date", "content");
        validate_presences($required_fields);

        $fields_with_max_length = array("project_name" => 30);
        validate_max_length($fields_with_max_length);

    $id = $current_project["id"];
    $project_name = mysql_prep($_POST["project_name"]);
    $date = mysql_prep($_POST["date"]);
    $content = mysql_prep($_POST["content"]);

    $target_dir = "images/";
$target_file = $target_dir . basename($_FILES["image_file"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

    print_r($_FILES);
    echo "<br>" . $target_file;

    if (empty($errors)) {
            if($_FILES["image_file"]["error"] == 4) {
            //means there is no file uploaded
            $query = "";
            $result = mysqli_query($connection, $query);

            if ($result && mysqli_affected_rows($connection) >= 0) {
                $_SESSION["message"] = "Subject Updated";
            //  redirect_to("manage_content.php?subject=$current_subject[id]");
            } 
        } else {
            $query = "";
            $result = mysqli_query($connection, $query);

            if ($result && mysqli_affected_rows($connection) >= 0) {
                $_SESSION["message"] = "Subject Updated";
            //  redirect_to("manage_content.php?subject=$current_subject[id]");

            } 
        }

    } else {
            $message = "Subject creation failed.";
            }  
    } else {
        // probably a get request
        // end of post submit
    }

?>

print_r($_FILES) ให้ฉัน:

Array ( [image_file] => Array ( 
  [name] => 1.jpg 
  [type] => image/jpeg 
  [tmp_name] => C:\xampp\tmp\phpF5AA.tmp 
  [error] => 0 
  [size] => 24397 ) 
) 
and echo $target_file gives: images/1.jpg

person bobo    schedule 22.08.2017    source แหล่งที่มา
comment
รหัสสำหรับย้ายไฟล์ที่อัพโหลดไปยังโฟลเดอร์อยู่ที่ไหน?   -  person Ravinder Reddy    schedule 22.08.2017
comment
คุณได้รับข้อผิดพลาดหรือไม่? บันทึกของคุณบอกว่าอย่างไร?   -  person ficuscr    schedule 22.08.2017
comment
ขอบคุณที่แก้ไขมัน :)   -  person bobo    schedule 22.08.2017


คำตอบ (1)


ตรวจสอบให้แน่ใจว่าไดเร็กทอรีที่คุณกำลังอัพโหลดนั้นมีสิทธิ์และความเป็นเจ้าของเหมือนกับโปรแกรมที่อัพโหลดไฟล์ ควรมีสิทธิ์ในการเขียนสำหรับผู้ใช้ เช่นเดียวกับไฟล์หากมีอยู่แล้ว คุณต้องมีสิทธิ์ในการเขียนเพื่อที่จะแทนที่ไฟล์

person Carl Powell III    schedule 22.08.2017