Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 649
Oldbej Avatar asked Oct 24 '25 23:10

Oldbej


2 Answers

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

like image 80
KoolKabin Avatar answered Oct 27 '25 12:10

KoolKabin


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.

like image 20
Evert Avatar answered Oct 27 '25 13:10

Evert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!