Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file_get_contents works on Local but not on server [duplicate]

Possible Duplicate:
file_get_contents() error

Working on a script that connects to Instagram API to get photos from a certain tag. It works just fine on Local but on the server i get errors.

Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /storage/content/91/103391/instaboll.nu/public_html/instagram.php on line 19.

This is how line 19 looks:
$contents = file_get_contents("https://api.instagram.com/v1/tags/$tag/media/recent?client_id=$client_id");

Any ideas?

Have searched for this and find some posts that recommend curl, but have no idea how to proceed with that.

like image 614
blytung Avatar asked Jun 11 '12 14:06

blytung


4 Answers

I solved it with this code.

<?php
$url = "http://www.example.org/";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$contents = curl_exec($ch);
if (curl_errno($ch)) {
  echo curl_error($ch);
  echo "\n<br />";
  $contents = '';
} else {
  curl_close($ch);
}

if (!is_string($contents) || !strlen($contents)) {
echo "Failed to get contents.";
$contents = '';
}

echo $contents;
?>    
like image 162
blytung Avatar answered Nov 03 '22 15:11

blytung


The solution is in the error message: set allow_url_fopen to 1 in your ini (use a php.ini file, use ini_set in php code, or talk to your host).

like image 27
Explosion Pills Avatar answered Nov 03 '22 15:11

Explosion Pills


You will have to enable allow_url_fopen from php.ini on your host or talk to your hosting providers.

This option enables the URL-aware fopen wrappers that enable accessing URL object like files.

like image 2
Sarfraz Avatar answered Nov 03 '22 14:11

Sarfraz


Your server admin has disabled this functionality. You'll need to ask them to enable it.

like image 2
cdhowie Avatar answered Nov 03 '22 13:11

cdhowie