无法修复错误“failed to open stream: HTTP wrapper does not support writeable connections”。

3
(注意:有人标记为重复问题,但我不知道是路径导致错误,其他问题与路径导致的错误有关,而我的问题不是。由于我不知道是路径导致了错误,所以无法通过其他问题解决我的问题)
你好,我有一个php项目,一直在尝试找到w3的图像上传教程,并且一直无法摆脱错误。我已经搜索了这些错误,而教程所做的就是任何解决方案建议的事情,所以我认为我只是忽略了一些显而易见的东西,请问有人可以帮忙吗?
HTML
<!DOCTYPE html>
<html>
<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>

PHP

<?php

ini_set('display_errors',1);
error_reporting(E_ALL);


$target_dir = "http://myDomainName.com/SchoolStore/Images/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$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) {
        //echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        //echo "File is not an image.";
        $uploadOk = 0;
    }
}
// Check if file already exists
if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "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)) {
        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading ". $target_file;
    }
}
?>

错误:

警告: move_uploaded_file(http://myDomainName.com/SchoolStore/Images/Screen Shot 2015-11-28 at 5.30.11 PM.png):无法打开流:HTTP包装器不支持可写连接,在/home1/tooneate/public_html/SchoolStore/upload.php的第43行

警告:move_uploaded_file():无法将'/var/tmp/phpc2F3xS'移动到'http://myDomainName.com/SchoolStore/Images/Screen Shot 2015-11-28 at 5.30.11 PM.png',在/home1/tooneate/public_html/SchoolStore/upload.php的第43行, 抱歉,上传http://myDomainName.com/SchoolStore/Images/Screen Shot 2015-11-28 at 5.30.11 PM.png时发生了错误

1个回答

7

不要使用

$target_dir = "http://myDomainName.com/SchoolStore/Images/"; 需要使用服务器路径

/SchoolStore/Images/ (例如 /home/content/proj/SchoolStore/Images/)。

你不能通过HTTP打开文件。相反,你需要使用本地路径打开。


这让我短暂地困惑了一下,但是对于未来查看本问题以获取正确路径的任何人,我必须登录我的托管服务并查看我的文件管理层次结构树。谢谢! - AwesomeTN

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接