How can I load a remote file using file_get_contents()?

有些话、适合烂在心里 提交于 2019-12-02 06:50:45

问题


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.

This works:

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

This doesn't:

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

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.

This is the error I get:

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 is set to On

Different domains


回答1:


check the php settings...

it may be due to security issue... "allow_url_fopen = On"

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




回答2:


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`

This would suggest you are either using an incorrect url, or DNS is not correctly set up on your server.



来源:https://stackoverflow.com/questions/10519238/how-can-i-load-a-remote-file-using-file-get-contents

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!