简体   繁体   中英

php Warning: move_uploaded_file(../images/uploads/tk13.JPG) [function.move-uploaded-file]: failed to open stream: Permission denied

I have this code for uploading an image to my webserver: upload_image.php:

<?php
function upload_image()
{
    $target_dir = "../images/uploads/";
    $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
    $uploadOk = true;
    $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
    if (isset($_POST["submit"])) {
        $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
        if ($check !== false) {
            $uploadOk = true;
        } else {
            $uploadOk = false;
            return "Sorry, file is not an image.";
        }
    }
// Check if file already exists
    if (file_exists($target_file)) {
        $uploadOk = false;
        return "Sorry, file already exists.";
    }
// Check file size
    if ($_FILES["fileToUpload"]["size"] > 200000000) {
        $uploadOk = false;
        return "Sorry, your file is too large.";
    }
// Allow certain file formats
    if ($imageFileType != "JPG" && $imageFileType != "PNG" && $imageFileType != "JPEG"
        && $imageFileType != "GIF"
    ) {
        $uploadOk = false;
        return "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    }
// Check if $uploadOk is set to 0 by an error
    if ($uploadOk == false) {
        return "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
    } else {
        if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
            return basename($_FILES["fileToUpload"]["name"]);
        } else {
            return "Sorry, there was an error uploading your file.";
        }
    }
}

It generates this error:

Warning: move_uploaded_file(../images/uploads/tk13.JPG) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/d36234/html/upload_image.php on line 40

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/var/apachefs/uploads/phpdMJhku' to '../images/uploads/tk13.JPG' in /home/d36234/html/upload_image.php on line 40

How do I fix this? The images is not being uploaded to the server. Would really appreciate help on this matter. 

右键单击文件夹,然后单击属性,您将在其中看到属性,然后取消选中只读,然后单击应用,然后单击确定。

Fixed this as Needhi suggested:

Right click on folder where you upload images to, and then click properties where you will see Attributes then uncheck the Read-Only and click on apply and then OK.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM