BurakUeda
06-14-2006, 10:02 AM
Hi,
I wonder if there is any trick in PHP to find out image size.
Say, I have an image at
http: //www . mysite . com / images / test1.jpg
Is there any way to parse size info about that image?
getimagesize() is retrieving the dimensions not the file size..
the--dud
06-14-2006, 10:03 AM
http://no.php.net/filesize
BurakUeda
06-14-2006, 10:19 AM
Thank you,
I actually am aware of that, however to use filesize() function, I have to get the image and save it to my server using gd library (imagecreatetruecolor, imagecreatefromjpeg, imagecopyresampled, imagejpeg), and then get the size using filesize function.
AFAIK, filesize is not working with "http://www", it must be a relative path like "/home/user/www/images/abcd.jpg"
anjanesh
06-14-2006, 01:27 PM
AFAIK, filesize is not working with "http://www", it must be a relative path like "/home/user/www/images/abcd.jpg" - will it work if url wrappers are On ?
brendandonhu
06-15-2006, 04:49 PM
filesize() only works on wrappers that support stat() (FTP wrappers as of PHP5 but not HTTP as far as I know)
There are example functions in the comments here to grab the Content-length header from remote files though: http://us3.php.net/filesize
Czaries
06-15-2006, 07:54 PM
Try this code:
<?php
function remote_file_size ($url)
{
$head = "";
$url_p = parse_url($url);
$host = $url_p["host"];
$path = $url_p["path"];
$fp = fsockopen($host, 80, $errno, $errstr, 20);
if(!$fp)
{ return false; }
else
{
fputs($fp, "HEAD ".$url." HTTP/1.1\r\n");
fputs($fp, "HOST: dummy\r\n");
fputs($fp, "Connection: close\r\n\r\n");
$headers = "";
while (!feof($fp)) {
$headers .= fgets ($fp, 128);
}
}
fclose ($fp);
$return = false;
$arr_headers = explode("\n", $headers);
foreach($arr_headers as $header) {
$s = "Content-Length: ";
if(substr(strtolower ($header), 0, strlen($s)) == strtolower($s)) {
$return = substr($header, strlen($s));
break;
}
}
return $return;
}
?>
From a quick google search (http://www.google.com/search?hl=en&lr=&q=php+remote+file+size&btnG=Search) found here (http://www.phptalk.com/forums/index.php/topic,4640.0.html)