php - 函数 file_get_contents() 返回 false
问题描述
我正在使用file_get_contents()
脚本中的函数。但它每次都被赋予错误的。
$image_url = 'http://www.websitename.com/images/imagename.jpg';
$variable = file_get_contents($image_url);
var_dump($variable);
它的回归false
我还检查phpinfo()
了服务器的设置。这里allow_url_fopen
已经on
我不知道为什么它返回错误。请帮我弄清楚这一点。提前谢谢了。
解决方案
在大多数情况下,这是您服务器的 SSL 证书的问题,影响最大
您可以使用此 hack 禁用 ssl 验证
$stream = stream_context_create(array(
'ssl'=>array(
'verify_peer'=> false,
'verify_peer_name'=> false, ),
'http' => array(
'timeout' => 30 ) ) );
$image_url = 'http://www.websitename.com/images/imagename.jpg';
$variable = file_get_contents($image_url,0,$stream);
var_dump($variable);