file_get_contents在本地但在服务器上不起作用 [英] file_get_contents works on Local but not on server
问题描述
可能重复:
file_get_contents()错误
Possible Duplicate:
file_get_contents() error
处理连接到Instagram API的脚本,以从特定标签获取照片.它在Local上工作正常,但在服务器上却报错.
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.
警告:file_get_contents():在服务器配置中,第19行的/storage/content/91/103391/instaboll.nu/public_html/instagram.php中的allow_url_fopen = 0禁用了https://包装器.
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.
第19行的外观如下:
$ contents = file_get_contents(" https://api.instagram.com/v1/tags/ $ tag/media/recent?client_id = $ client_id);
This is how line 19 looks:
$contents = file_get_contents("https://api.instagram.com/v1/tags/$tag/media/recent?client_id=$client_id");
有什么想法吗?
已经搜索了此内容,并找到了一些推荐使用curl的帖子,但不知道如何进行.
Have searched for this and find some posts that recommend curl, but have no idea how to proceed with that.
推荐答案
我用这段代码解决了它.
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;
?>
这篇关于file_get_contents在本地但在服务器上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!