I am trying to create a site that use amazon api to display book information. However, some images I downloaded is showing 0 byte. The code is running on a virtual serever, so curl is enabled.
For example, this image: http://ecx.images-amazon.com/images/I/51d1Zp4f80L.SL75.jpg
My code is this:
try
{
$ch = curl_init($coverImageUrl);
$imgName = "images/".$isbn.".png"; //assume png
$imgFullPath = $_SERVER['DOCUMENT_ROOT']."/".$imgName;
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$fb = curl_exec($ch);
if($fb === false) {
echo 'something wrong';
}
curl_close($ch);
file_put_contents( $imgFullPath, $fb );
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "
";
die("problem with image");
}