HTTP包装器不支持移动上载文件中的可写连接

时间:2014-11-07 08:25:01

标签: php file

我正在尝试将文件从本地上传到服务器

我收到此错误 HTTP包装器不支持可写连接

我正在使用此代码

$target_path="http://www.example.net/entities/"; 
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { 

    echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";

} else{
    echo "There was an error uploading the file, please try again!";
}

是,有任何方法可以将文件从本地上传到服务器

由于

3 个答案:

答案 0 :(得分:1)

据我所知,您尝试将文件从本地服务器上传到远程服务器,并且您提供的代码位于本地服务器中。比不可能。

使用ftp_put()通过FTP将文件上传到远程服务器。

如果您的代码位于远程服务器(您尝试保存文件的位置),而不是提供服务器路径而不是该目录的URL。要获取该目录的路径,只需使用代码echo dirname(__FILE__) (or echo __DIR__ as of PHP >= 5.3.0)创建文件即可获取该目录的服务器路径。

答案 1 :(得分:1)

您不能将move_uploaded_file与网址/远程路径一起使用,例如' example.com/example /'尝试本地路径,例如' ./ example /'它将cosider作为&example; example.com/example /

$target_path="./entities/";  // example.com/entities/
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path .$_FILES['uploadedfile']['name'])) { 

   echo 'uploaded';

} else{
    echo "There was an error uploading the file, please try again!";
}

答案 2 :(得分:0)

您的目标路径应该类似于

$target_path = $_SERVER['DOCUMENT_ROOT'] . "/entities/";

我希望这可以帮助任何人通过这个 HTTP 包装器不支持可写连接