file_get_contents无法打开流:HTTP请求失败! HTTP/1.1 500内部服务器错误 [英] file_get_contents failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error

查看:744
本文介绍了file_get_contents无法打开流:HTTP请求失败! HTTP/1.1 500内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过URL从外部源检索图像并将其保存到我的Web服务器. Unfortaley有时会出现以下错误:无法打开流:HTTP请求失败! HTTP/1.1 500内部服务器错误.

I'm retrieving and saving images from a external source to my webserver by URL's. Unfortaley sometimes I get the following error: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error.

当我使用浏览器访问给定的URL时,图像将显示并有效.网址:

When I visit the given url with my browser the image is shown and valid. The url:

http://****.com/00/s/NTgwWDcyNg==/z/7LEAAMXQVT9TCcxx/$_85.JPG

我使用的代码:

$opts = array('http'=>array('header' => "User-Agent:Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.75 Safari/537.1\r\n", 'timeout' => "360"));
$context = stream_context_create($opts);                                         
$imageString = file_get_contents(urldecode(urlencode($filename)), false, $context);                                            
$save = file_put_contents(dirname(dirname(__FILE__)) . '/tmp/' . $id . '_' . $sequenceNumber . '.jpg', $imageString);

有人知道为什么我会出现500错误吗?

Anyone has a idea why I get a 500 error?

推荐答案

以下答案对我有用:

这篇关于file_get_contents无法打开流:HTTP请求失败! HTTP/1.1 500内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆