file_get_contents适用于本地但不适用于服务器

bly*_*ung 7 php file-get-contents

可能重复:
file_get_contents()错误

处理连接到Instagram API的脚本以从特定标签获取照片.它在Local上工作正常,但在服务器上我得到错误.

警告:在第19行的/storage/content/91/103391/instaboll.nu/public_html/instagram.php中,allow_url_fopen = 0在服务器配置中禁用了file_get_contents():https://包装器.

第19行看起来是这样的:
$ contents = file_get_contents(" https://api.instagram.com/v1/tags/ $ tag/media/recent?client_id = $ client_id");

有任何想法吗?

已搜索过这个并找到一些推荐curl的帖子,但不知道如何继续.

bly*_*ung 17

我用这个代码解决了它.

<?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;
?>    
Run Code Online (Sandbox Code Playgroud)

  • 我碰到了这个,发现了你的线程,但需要使用cURL的cookie和其他有用的东西.我最后在下面的帖子中发布我的解决方案,如果它对其他人有用.http://stackoverflow.com/questions/12885538/php-curl-and-cookies (2认同)