-2

我正在尝试从here

上面的 url 同时使用 php curl 和 file_get_content。但是当我使用 php curl 时,图像已下载但没有内容,当我使用file_get_content时出现以下错误,

Warning: file_get_contents(http://s3.amazonaws.com/test_bucket/test_12_12_2013_10_51_00.jpg) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 505 HTTP Version Not Supported in /home/webdev/public_html/example/photos/download.php on line 11

4

1 回答 1

1

首先,您提供的链接不是图像。它输出..

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>AllAccessDisabled</Code>
<Message>All access to this object has been disabled</Message>
<RequestId>35DFBD44D75B45C4</RequestId>
<HostId>
n1TT+gOUuMJ3RydGND/s3QL73JJEadz/2uQutK4NNUDbEaGX6EI0Y8a/6eDHLR6H
</HostId>
</Error>

测试和工作!

下面的代码从 URL 读取图像,保存它,然后在浏览器上打开/呈现。

<?php
$image ="http://blog.stackoverflow.com/wp-content/uploads/stackoverflow-logo-300.png";
$ch = curl_init($image);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec ($ch);
curl_close ($ch);
$fp = fopen("test.jpg",'w');
fwrite($fp, $rawdata);
fclose($fp);
header ("Content-Type: image/png");
readfile("test.jpg");

输出 :

在此处输入图像描述

或者

如果你只想渲染它.. 这样做。

<?php
readfile("http://blog.stackoverflow.com/wp-content/uploads/stackoverflow-logo-300.png");
header ("Content-Type: image/png");
于 2013-12-13T09:56:36.597 回答