7

我只是使用 file_get_contents 来检索我网站中的数据。但它不返回任何东西。

file_get_contents("https://www.google.co.in/images/srpr/logo11w.png")

当我在本地环境中使用它时,它会返回值。

我还在我的网站上尝试了 curl 以确定它是否返回任何内容。但它显示

Forbidden
您没有访问权限。

我用谷歌搜索,我发现了一些提示。我启用了 allow_url_fopenallow_url_include

但没有任何工作。

我尝试过的卷曲代码

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;
4

1 回答 1

2

方式file_get_contents()...

<?php
header('Content-Type: image/png');
echo file_get_contents("https://www.google.co.in/images/srpr/logo11w.png");

方式cURL...

<?php
header('Content-Type: image/png');
function curl($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
    $return = curl_exec($ch); curl_close ($ch);
    return $return;
}
$string = curl('https://www.google.co.in/images/srpr/logo11w.png');
echo $string;

输出 :

在此处输入图像描述

于 2014-01-02T07:26:21.580 回答