Solved : fopen and fread not working with url in php

Many times we normally face problems while reading a file using url. Due to wrong PHP configuration we are facing fopen and fread not working with url issue.

fopen and fread not working with url

Using following solution we can easily fix this PHP issue.
For e.g :
$url = ‘http://somesite.com/somefile.txt’;
$fp = fopen($url,”r”);

To allow the fopen to get the contents of the file through url, do the following settings in php.ini file :

allow_url_include = On

By setting above 2 directives to ‘On’, fopen will be able to read the contents from url.

If you are using wamp than we can change this setting by on clicking on wamp icon and than go to PHP and click on setting > and allow_url_fopen option setting.

For linux users, you need to change /etc/php.ini file and do not forget to restart to apache server.

2 Comments

Add a Comment

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