I Was Using This Code to Get Image size in php and it was working Perfectly For Me.
$img = get_headers("http://ultoo.com/img_single.php", 1);
$size = $img["Content-Length"];
echo $size;
But How Get this through CURL ? I Tried This But Doesn't Work.
$url = 'http://ultoo.com/img_single.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, "Content-Length" );
//curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
$filesize = $result["Content-Length"];
curl_close($ch);
echo $filesize;
set curl_setopt($ch, CURLOPT_HTTPHEADER, true );
,then print_r($result)
,you will see something like
HTTP/1.1 200 OK
Date: Tue, 04 Jun 2013 03:12:38 GMT
Server: Apache/2.2.15 (Red Hat)
X-Powered-By: PHP/5.3.3
Set-Cookie: PHPSESSID=rtd17m2uig3liu63ftlobcf195; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 211
Content-Type: image/png
I don't think Content-Length
is the right way to get image size,because I get different result between curl
and get_header
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With