问题
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