可能的重复项:
file_get_contents() 错误
处理连接到Instagram API的脚本,以从特定标签获取照片。它在本地工作得很好,但在服务器上我收到错误。
警告:file_get_contents():https://包装器在服务器配置中被禁用,在第 19 行的/storage/content/91/103391/instaboll.nu/public_html/instagram.php 中通过 allow_url_fopen=0 禁用。
这是第 19 行的外观:
$contents = file_get_contents("https://api.instagram.com/v1/tags/$tag/media/recent?client_id=$client_id");
有什么想法吗?
已经搜索了这个并找到了一些推荐 curl 的帖子,但不知道如何继续。
我用这段代码解决了它。
<?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;
?>
解决方案在错误消息中:在 ini 中将allow_url_fopen
设置为 1
(使用 php.ini
文件,在 php 代码中使用 ini_set
,或与您的主机交谈)。
您必须在主机上启用来自php.ini的allow_url_fopen
或与您的托管服务提供商交谈。
此选项启用 URL 感知的 fopen 包装器,该包装器允许访问 URL 对象,如文件。
您的服务器管理员已禁用此功能。 您需要要求他们启用它。