2

For some reason file_get_contents isn't allowing me to get files which are on the same server.

This is the error I'm getting:

file_get_contents(http://www.my-url.com/image.jpg): failed to open stream: Connection refused

I know I can use the system path to get files but in this case I need to be able to test this with the URL.

Marc B
  • 356,200
  • 43
  • 426
  • 500
Raven87
  • 33
  • 3
  • Check your php.ini, is the "allow_url_fopen = On". – vaso123 Nov 06 '14 at 13:40
  • If they're on the same server, why don't you use the file-system path? – jeroen Nov 06 '14 at 13:47
  • the allow_url_fopen is already On, and I can't use the system path because I'm using a WordPress function that needs an URL – Raven87 Nov 06 '14 at 13:54
  • please refer to [this question](http://stackoverflow.com/questions/3488425/php-ini-file-get-contents-external-url) Hope this helps. – Vanitas Nov 06 '14 at 14:09
  • If they're on the same server, then DON'T use a full-blown http request. That's massively wasteful. Use the local filesystem path, e.g. `file_get_contents('/home/sites/my-url.com/html/image.jpg')` – Marc B Nov 06 '14 at 14:11
  • I realize it's wasteful and using a local filesystem path is more effective, I'm just unable to do it in this case. Also @Vanitas allow_url_fopen is already turned On, and cURL isn't working either. – Raven87 Nov 06 '14 at 14:40

1 Answers1

1

Even if the file you are opening is on your server if you are using the url rather than the directory mechanism, you will need to set

allow_url_fopen = On

In you php.ini file.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149