Let\'s say we have an image file, stored in a remote server (for example, let\'s take this image), how can we determine (in PHP code) it\'s file size?
If the file wa
echo get_headers($url,1)['Content-Length'];
Assuming you're worried about the size of the file (not the dimensions of the image), you can grab Content-Length and it will usually work.
If the server on the other end does't supply the header, you'll have no choice but to GET the file, and check its size locally.
<?PHP
$headers = get_headers('http://humus101.com/wp-content/uploads/2009/11/Hummus-soup.jpg');
$size = null;
foreach($headers as $h){
/** look for Content-Length, and stick it in $size **/
}
if ($size === null){ //we didn't get a Content-Length header
/** Grab file to local disk and use filesize() to set $size **/
}
echo "image is $size bytes";
Someone else has a function for that that basically does it as a socket connection: http://snippets.dzone.com/posts/show/1207