gpt4 book ai didi

php - 如何使用 file_get_contents() 加载远程文件?

转载 作者:行者123 更新时间:2023-12-04 02:18:16 32 4
gpt4 key购买 nike

现在我有点摸不着头脑了。
我正在尝试从远程 url 获取文件。我可以从本地文件保存内容,但不能从远程保存。

这个有效:

file_put_contents(
'file1.xml',
file_get_contents('file2.xml')
);

这不是:

file_put_contents(
'file1.xml',
file_get_contents('http://www.domain.com/xmlapi/search.aspx?query=places&lid=38')
);

奇怪的是,我的其他脚本在第一次尝试时工作正常,但现在没有人会访问远程 url。
我最近开始在 Heart Internet 上托管我的新 php 文件。我在其他服务器上有类似的脚本,完全没有问题。

这是我得到的错误:

Warning: file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/sites/mydomain/myfile.php on line 5`

Warning: file_get_contents(http://www.domain.com/xmlapi/search.aspx?query=places&lid=38) [function.file-get-contents]: failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/sites/mydomain/public_html/myfile.php on line 5`

allow_url_fopen 设置为 On

不同的域

最佳答案

检查 php 设置...

这可能是由于安全问题... "allow_url_fopen = On"

http://www.php.net/manual/en/function.file-get-contents.php

关于php - 如何使用 file_get_contents() 加载远程文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10519238/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com