file_get_contents未能打开流:HTTP请求失败!HTTP/1.1 500内部服务器错误。

时间:2022-05-23 01:51:55

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检索和保存从外部源到我的webserver的图像。不幸的是,有时我有以下错误:失败的开放流:HTTP请求失败!HTTP/1.1 500内部服务器错误。

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

当我用我的浏览器访问给定的url时,图像是显示和有效的。网址:

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

The code which I use:

我使用的代码:

$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);

Anyone has a idea why I get a 500 error?

有人知道为什么我有500个错误吗?

1 个解决方案

#1


5  

The following answer worked for me: PHP file_get_contents 500 Internal Server error

下面的答案为我工作:PHP file_get_contents 500内部服务器错误。

$opts = array('http' => array('header' => "User-Agent:MyAgent/1.0\r\n"));
$context = stream_context_create($opts);
$header = file_get_contents('https://www.example.com', FALSE, $context);

#1


5  

The following answer worked for me: PHP file_get_contents 500 Internal Server error

下面的答案为我工作:PHP file_get_contents 500内部服务器错误。

$opts = array('http' => array('header' => "User-Agent:MyAgent/1.0\r\n"));
$context = stream_context_create($opts);
$header = file_get_contents('https://www.example.com', FALSE, $context);