I hosted images in Amazon S3. And I point the URL static.example.com
to S3 Bucket. When I directly enter the URL http://static.example.com/path/mypic.png
in browser the image is existed, I can view and download too. But when I want to get the size and dimension of image in PHP it is showing this error.
`getimagesize($path)`
And this is the error.
A PHP Error was encountered
Severity: Warning
Message: getimagesize(http://static.example.com/path/mypic.png) [function.getimagesize]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
Filename: views/template.php
Line Number: 98
I can store the size in database while uploading but that is not the solution for me, I already have 1000x images in S3. When I do @ getimagesize($path)
the errors are not showing but no size, no dimension.
I also looked into PHP documentation getimagesize (URL). The link example is suppose to support remote images.
Checking php.ini
Directive Local Value Master Value
allow_url_fopen On On
Where I am wrong? Is there better way to get image size and dimension of remote image in PHP?
NOTE I am 100% sure the remote image path is correct.
Check your php.ini
file. The most likely cause is that your server isn't set to enable allow_url_fopen
. This is a setting that is sometimes disabled by default as a security precaution.
Also, as an aside, once you get this working you might want to make sure you're caching the results because getimagesize
will download the entire remote image before returning results, which will put a lot of drag on your server.
On this last point, you might want to check out FastImage as suggested by baba... and it might just avoid the problem altogether if this issue isn't enable allow_url_fopen
.