View Single Post
Old 09-20-2007, 02:17 PM   #2 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Sometimes the remote server will return you the Content-Length in the HTTP header. However, failing that, the way I would do it is:

PHP Code:
$szFile file_get_contents('http://www.google.co.uk/intl/en_uk/images/logo.gif');
echo 
round(strlen($szFile) / 10242) . 'KB'
This is assuming that all the characters are 1 byte a piece. 2 byte characters, such as Japanese characters, will give a bad reading, but you should be fine.

Needless to say that the Content-Length in the header is the way forward because the file doesn't need to be downloaded first - this is fine though with smallish files.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote