如何使用file_get_contents()加载远程文件? [英] How can I load a remote file using file_get_contents()?
问题描述
现在用这个挠头.
我正在尝试从远程URL获取文件.我可以从本地文件中保存内容,但不能从远程文件中保存.
Scratching my head a bit now with this.
I am trying to get a file from a remote url. I can save contents from local files, but can't from remote.
这有效:
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文件.我在其他服务器上也有类似的脚本,这些脚本完全没有问题.
Oddly enough my other scripts worked ok at first try but none will access the remote url now.
I have recently started to host my new php files on Heart Internet. I have similar scripts on other servers which give no problems at all.
这是我得到的错误:
警告:file_get_contents()[function.file-get-contents]:php_network_getaddresses:getaddrinfo失败:名称或服务在第5行的/home/sites/mydomain/myfile.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`
警告:file_get_contents( http://www.domain .com/xmlapi/search.aspx?query = places& lid = 38 )[function.file-get-contents]:无法打开流:php_network_getaddresses:getaddrinfo失败:/home/中未知的名称或服务第5行上的sites/mydomain/public_html/myfile.php`
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设置...
check the php settings...
这可能是由于安全问题导致的."allow_url_fopen = On"
it may be due to security issue... "allow_url_fopen = On"
http://www.php.net/manual/zh/function.file-get-contents.php
这篇关于如何使用file_get_contents()加载远程文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!