【发布时间】:2015-01-03 01:02:27
【问题描述】:
由于某种原因,file_get_contents 不允许我获取位于同一服务器上的文件。
这是我得到的错误:
file_get_contents(http://www.my-url.com/image.jpg): failed to open stream: Connection refused
我知道我可以使用系统路径来获取文件,但在这种情况下,我需要能够使用 URL 进行测试。
【问题讨论】:
-
检查你的php.ini,是不是“allow_url_fopen = On”。
-
如果它们在同一台服务器上,为什么不使用文件系统路径?
-
allow_url_fopen 已经开启,我无法使用系统路径,因为我正在使用需要 URL 的 WordPress 函数
-
请参考this question希望对您有所帮助。
-
如果他们在同一台服务器上,那么不要使用成熟的 http 请求。这是非常浪费的。使用本地文件系统路径,例如
file_get_contents('/home/sites/my-url.com/html/image.jpg')
标签: php apache file-get-contents