PHP move_uploaded_file权限被拒绝

时间:2012-07-30 05:34:07

标签: php file-upload permission-denied

我一直在尝试将图片从表单移动到我的网站上的上传文件夹,该文件由godaddy托管。使用move_uploaded_file()方法时,我收到权限被拒绝错误。我在这个问题上经历了很多问题,但是他们都没有解决我的问题。另外,我已将权限更改为777。

以下是我遇到的错误:

  

警告:move_uploaded_file()[function.move-uploaded-file]:无法执行   将'D:\ Temp \ php \ php42C0.tmp'移动到   'upload / vZvD6WI4vkapbCLovWtrSIG3xPLD0E.jpeg'中   第80行的D:\ Hosting \ 11111 \ html \ dir \ upload_image \ formsubmit.php

PHP代码:

$name = $_POST['name'];
$email = $_POST['email'];

if(isEmpty($name) || isEmpty($email)) {
    print '<b>Please go back to the previous page and fill out your name.</b>';
}
else {

$file_name = "file1";
    if ((($_FILES[$file_name]["type"] == "image/gif")
     || ($_FILES[$file_name]["type"] == "image/jpeg")
     || ($_FILES[$file_name]["type"] == "image/jpg")
     || ($_FILES[$file_name]["type"] == "image/bmp")
     || ($_FILES[$file_name]["type"] == "image/tiff")
     || ($_FILES[$file_name]["type"] == "image/png")
     || ($_FILES[$file_name]["type"] == "image/pjpeg"))
     && ( ($_FILES[$file_name]["size"] < 10000000) && $_FILES[$file_name]["size"] > 0) )
    {
        if ($_FILES[$file_name]["error"] > 0)
        {
            print "There was an error in uploading your images: " . $_FILES[$file_name]["error"] . "<br />";
        }
        else
        {
            if (file_exists("upload/" . $rand_img_name.".jpeg") )
            {
                print "Please try uploading your image again<br />";
            }
            else
            {
                move_uploaded_file($_FILES[$file_name]["tmp_name"],
                "upload" ."/". $rand_img_name.".jpeg");
                $files_are_valid[($i-1)] = true;
            }
        }
    }
    else
    {
        print 'Image must be a valid image under 10 MB (Make sure you submitted an image)<br />';
        $files_are_valid[($i-1)] = false;
    }
}

if($files_are_valid[0] == true) {
    $all_valid = true;
}
else {
    $all_valid = false;
}

1 个答案:

答案 0 :(得分:7)

这是一个Windows服务器(路径中的斜杠将其丢弃)。因此,您需要通过GoDaddy权限面板设置权限。您需要为uploads目录设置读/写权限。通过FTP设置777不会在Windows服务器上删除它。

http://support.godaddy.com/help/article/6481/setting-directory-permissions-with-windows-hosting-accounts/