无法修复错误“无法打开流:HTTP包装器不支持可写连接”[重复](Can't fix error “failed to open stream: HTTP wrapper does not support writeable connections” [duplicate])

这个问题在这里已有答案:

当Unix系统 4答案中 给出完整的Web路径时,PHP move_uploaded_file不上传图像

(注意无论谁将其标记为重复,我都不知道它是导致错误的路径,其他问题是导致错误的路径特有的,我的问题不是。因为我不知道这是路径导致错误,我无法用其他问题解决我的问题)

您好我有一个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 /中的可写连接第43行的public_html / SchoolStore / upload.php

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

This question already has an answer here:

PHP move_uploaded_file is Not uploading Images when full web path is given in Unix system 4 answers

(Note to whoever marked it as duplicate, I did not know it was the path that was causing the error, the other questions was specific to the path causing the error, my question was not. Since I had no idea it was the path that was causing the error, there was no way for me to solve my problem with that other question)

Hello I have a php project and I have been trying to figure out an image upload tutorial for w3 and have been unable to get rid of errors. I have searched the errors and the tutorial does what any solution suggests so I think Im just missing something obvious, can someone please help.

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; } } ?>

Errors:

Warning: move_uploaded_file(http://myDomainName.com/SchoolStore/Images/Screen Shot 2015-11-28 at 5.30.11 PM.png): failed to open stream: HTTP wrapper does not support writeable connections in /home1/tooneate/public_html/SchoolStore/upload.php on line 43

Warning: move_uploaded_file(): Unable to move '/var/tmp/phpc2F3xS' to 'http://myDomainName.com/SchoolStore/Images/Screen Shot 2015-11-28 at 5.30.11 PM.png' in /home1/tooneate/public_html/SchoolStore/upload.php on line 43 Sorry, there was an error uploading http://myDomainName.com/SchoolStore/Images/Screen Shot 2015-11-28 at 5.30.11 PM.png

最满意答案

而不是做

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

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

您无法通过HTTP打开文件。 相反,您需要使用本地路径打开它。

Instead of doing

$target_dir = "http://myDomainName.com/SchoolStore/Images/"; you need to use the server path to

/SchoolStore/Images/ (e.g. /home/content/proj/SchoolStore/Images/).

You cannot open a file via HTTP. Instead you need to open it using the local path.

更多推荐