File_Get_Contents Not Working

file_get_contents( ) not working

Login to your server via ssh and type

sudo nano /etc/php5/apache2/php.ini //<<<< ubuntu/debian server, might differ for you

in the file, simply press "ctrl + w" and type "allow_url_fopen" and Return, most probably you will come to the explanation first, so repeat the search a couple of times. Now you can change the entry from

allow_url_fopen=0

to

allow_url_fopen=1

press "ctrl + x" and confirm the file save with "y".

Then type

sudo service apache2 restart

This will restart apache so the new php.ini configuration can be loaded. After those steps, you should be able to use file_get_contents externally.


SIDENOTE

If you can't find your php.ini file, you will find the path to the loaded php.ini file in the top section of your phpinfo()

Sample Image

file_get_contents not working with variable PHP

Follow @CBroe way. I'm used var_dump and see the length is different. After many checking I found the variable is hex code http://i132.photobucket.com/albums/q13/animalhelper2006/1376.jpg
Final I used html_entity_decode function and it working fine now.

$contents = file_get_contents(html_entity_decode($imageurl));

PHP : file_get_contents not working properly

Try the below code, this will make sure that you're stuff is properly URI encoded.

$params = [
'token' => $_GET['token'],
'agencyName' => $_GET['agency'],
'stopName' => $_GET['stopname']
];

$file = file_get_contents(sprintf("http://services.my511.org/Transit2.0/GetNextDeparturesByStopName.aspx?%s", http_build_query($params));
echo(json_encode(simplexml_load_string($file)));


Related Topics



Leave a reply



Submit