9

I am using file_get_contents on my PHP and it throws some errors:

My code

#try to fetch from remote
$this->remotePath = "http://some-hostname.com/blah/blah.xml
$fileIn = @file_get_contents($this->remotePath);

The errors:

Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /virtual/path/to/file/outputFile.php on line 127

Warning: file_get_contents(https://some-host-name/data/inputFile.xml) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /virtual/path/to/file/outputFile.php on line 127

Any idea? It worked fine in my computer but stopped working when I ported it to the web server.

Tu Hoang
  • 4,622
  • 13
  • 35
  • 48

2 Answers2

16

Your server must have the allow_url_fopen property set to true. Being on a free webhost explains it, as it's usually disabled to prevent abuse. If you paid for your hosting, get in contact with your host so they can enable it for you.

If changing that setting is not an option, then have a look at the cURL library.

  • Do you know any way to work around that because that file is from a remote server, not from my internal server. – Tu Hoang Jul 01 '11 at 17:49
  • You might get away with doing it on your own via ini_set('allow_url_fopen', 1) but there's a good chance that's locked down as well. – David Souther Jul 01 '11 at 17:55
  • My host set `allow_url_fopen` to off but enabled `curl`. In how far does that make sense (from their perspective)? – Martin Thoma May 15 '14 at 18:16
5

It seems "allow_url_fopen" setting is false on your server and hence does not allow using URLs with file_get_contents().

Try using CURL instead that is a better and efficient way of communicating with other server.

Abhay
  • 6,545
  • 2
  • 22
  • 17