-2

から画像をダウンロードしようとしていますhere

php curl と file_get_content の両方を使用して上記の URL を取得します。しかし、私が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 に答える