问题
I have been attempting to move images from a form to an upload folder on my website which is hosted by godaddy. When using the move_uploaded_file() method, I get a permission denied error. I have gone through quite a few questions on this subject, but none of them have yet solved my problem. Also, I have changed my permissions to 777.
Here is the Error I have been getting:
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\Temp\php\php42C0.tmp' to 'upload/vZvD6WI4vkapbCLovWtrSIG3xPLD0E.jpeg' in D:\Hosting\11111\html\dir\upload_image\formsubmit.php on line 80
PHP Code:
$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:
This is a Windows server (the slashes in the paths give it away). So you need to set permissions through the GoDaddy permissions panel. You need to set read/write permissions for uploads directory. Setting 777 by FTP doesn't cut it on Windows servers.
http://support.godaddy.com/help/article/6481/setting-directory-permissions-with-windows-hosting-accounts/
来源:https://stackoverflow.com/questions/11715882/php-move-uploaded-file-permission-denied