php 警告:move_uploaded_file(../images/uploads/tk13.JPG) [function.move-上传文件]:无法打开流:权限被拒绝
php Warning: move_uploaded_file(../images/uploads/tk13.JPG) [function.move-uploaded-file]: failed to open stream: Permission denied
我有这段代码可以将图片上传到我的网络服务器:
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
我该如何解决这个问题?图像未上传到服务器。
真的很感激在这件事上的帮助。
右键单击文件夹并单击属性,您将在其中看到“属性”,然后取消选中“只读”并单击“应用”,然后单击“确定”。
按照 Needhi 的建议修复了此问题:
右键单击要上传图像的文件夹,然后单击属性,您将在其中看到属性,然后取消选中只读,单击应用,然后单击确定。
我有这段代码可以将图片上传到我的网络服务器: 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
我该如何解决这个问题?图像未上传到服务器。 真的很感激在这件事上的帮助。
右键单击文件夹并单击属性,您将在其中看到“属性”,然后取消选中“只读”并单击“应用”,然后单击“确定”。
按照 Needhi 的建议修复了此问题:
右键单击要上传图像的文件夹,然后单击属性,您将在其中看到属性,然后取消选中只读,单击应用,然后单击确定。