【发布时间】:2014-01-19 14:56:11
【问题描述】:
我刚刚使用 file_get_contents 来检索我网站中的数据。但它不返回任何东西。
file_get_contents("https://www.google.co.in/images/srpr/logo11w.png")
当我在本地环境中使用它时,它会返回值。
我还在我的网站上尝试了 curl 以确定它是否返回任何内容。 但它显示了
禁止
您没有访问权限。
我搜索了一下,发现了一些提示。我启用了 allow_url_fopen 和 allow_url_include。
但没有任何效果。
我尝试过的 curl 代码
function curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$return = curl_exec($ch); curl_close ($ch);
return $return;
}
$string = curl('https://www.google.co.in/images/srpr/logo11w.png');
echo $string;
【问题讨论】:
-
你能告诉我们你的 curl 尝试的代码吗? PS:你确定不是你的服务器问题?我刚刚检查过,它在该特定链接上对我来说很好。
-
@Dainis Ablos:我已经更新了这个问题。看看就好。
-
正如我所说,您的主机可能会阻止对外部资源的调用。 Here 是您在我的服务器上未更改的脚本,它工作得很好。
-
vinothavn - 你查到真相了吗?我有同样的问题。我已经确认 allow_url_fopen 设置为“开”。如果有人对“主机可能阻止对外部资源的调用”(根据@Dainis Abols 的 cmets)有任何想法,我也会很感激 - 在这种情况下,外部资源实际上最终是本地的,但它是渲染的( json) 本地文件的输出,而不是我想要的文件源的内容。
标签: php curl file-get-contents phpinfo