Back to Top

How to access Remote File using PHP

The light had gone to my office yesterday so I utilize my time.I just pick up my mobile and was started writing an article.

Before few days, I was working in one site which is in WordPress and I want to fetch twitter latest tweet and I have used one of the plugins in WordPress to fetch twitter latest tweets and what happened is tweets fetched in local but it was not loading on live server.

After that, I have debugged code and found that allow_url_fopen function is used to fetch tweets from twitter and allow_url_fopen function is off in live web server. Mostly this PHP parameter allow_url_fopen has been disabled by default on live server and that means that once allow_url_fopen is set as off, your application cannot retrieve remote files at all.

If allow_url_fopen is off, can’t retrieve remote files or remote URL in PHP.The open() function and the include and require directives can retrieve remote files if allow_url_fopen is on and we can set this by php.ini or by .htaccess.

To open remote files with fopen() is implemented by a PHP feature called the URL fopen wrapper. It’s enabled by default but if it’s disabled by setting allow_url_fopen to off. If you can’t open/access remote files with fopen(), check your server configuration.


If you have an access of php.ini file then you just need to place the below code in your php.ini file or replace the existing parameters with below one:

allow_url_fopen = On


Now if you don’t have an access to your php.ini then you can change these parameters from the .htaccess file as well. copy below code in your .htaccess file and you are ready to go.

php_value allow_url_fopen on

Here are the couple of articles which you should definitely read

To change File/Image Upload Path in WordPress
change the file ownership Ubuntu
To Create a Temporary File in PHP

I hope you have enjoyed this article. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Comments (2)

  1. Hi there

    Thanks your articles are really informative. Thank you

  2. Iˇm now not certain the place you’re getting your info, however good topic. I must spend some time finding out more or figuring out more. Thanks for wonderful info I was on the lookout for this info for my mission.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How to allow External domain in WordPress?

Posted on 4 years ago


What is Type Hinting in PHP5

Posted on 7 years ago


Understanding of Polymorphism in PHP

Posted on 2 years ago


What are Lambdas and Closures in PHP?

Posted on 2 years ago


Hello world

Updated 1 month ago

Nick Carter

In depth Understanding of Laravel Core

Updated 3 months ago


ECMAScript 6 New Features – 2

Updated 1 year ago


The Reader’s Poll – June 2015

Posted on 4 years ago


The Reader’s Poll – August 2014

Posted on 5 years ago


The Reader’s Poll – June 2014

Posted on 5 years ago


The Readers’ Poll – May 2014

Posted on 5 years ago


The Readers’ Poll – August 2013

Posted on 6 years ago