【问题标题】:PHP - file_put_contents not working on server [duplicate]PHP - file_put_contents 在服务器上不起作用[重复]
【发布时间】:2014-05-14 15:42:34
【问题描述】:

我正在尝试使用以下代码更新我们服务器上的 XML 文件:-

$dom = $jobsXML->asXML();

file_put_contents("http://www.address.com/scripts/xml/jobs.xml", $dom) or print_r(error_get_last());;

我收到以下错误消息:-

[type] => 2
[message] => file_put_contents(http://www.address.com/scripts/xml/jobs.xml): failed to open stream: HTTP wrapper does not support writeable connections
[file] => /var/www/vhosts/address.com/httpdocs/scripts/php/jobs.controller.php
[line] => 78

该文件设置为 chmod 777,因此它是可写的,并且在服务器上启用了 file_put_contents 功能。

为什么这个文件不能被写入?

【问题讨论】:

  • 我认为问题是由于使用 HTTP 并且路径不匹配;如果 FTP 端口打开,请尝试使用 FTP
  • file_put_contents不会为您进行 http 上传。

标签: php


【解决方案1】:

您需要定义路径,而不是域 url。

例如:

$dom = $jobsXML->asXML();

file_put_contents("scripts/xml/jobs.xml", $dom) or print_r(error_get_last());

来源:failed to open stream: HTTP wrapper does not support writeable connections

【讨论】:

  • 谢谢,现在开始工作! :) 只是为了添加你可以使用 echo $_SERVER['DOCUMENT_ROOT'] ?> 如果有人不确定
【解决方案2】:
HTTP wrapper does not support writeable connections

尝试在您的文件系统上指定一个路径。

例如。 file_put_contents('myfile.data'.$data);

【讨论】:

    猜你喜欢
    • 2015-10-02
    • 1970-01-01
    • 2012-08-26
    • 1970-01-01
    • 2012-01-12
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多