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.

1) PHP.INI METHOD

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:

2) .HTACCESS METHOD

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.

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.

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

Most Popular Posts

How To Install Bugzilla on Windows

Posted on 11 years ago

Bhumi

How to use Replace function in MySQL

Posted on 11 years ago

Bhumi