php警告:move_uploaded_file(../ images / uploads / tk13.JPG)[function.move-uploaded-file]:无法打开流:权限被拒绝

时间:2015-01-08 09:56:35

标签: php

我有这个代码用于将图像上传到我的网络服务器: 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.";
        }
    }
}

它会生成此错误:

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

我该如何解决这个问题?图像未上载到服务器。 非常感谢这件事的帮助。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

修正了这个问题,因为Needhi建议:

右键单击要上载图像的文件夹,然后单击属性,您将看到属性,然后取消选中只读,然后单击应用,然后单击确定。