PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
anjanesh
DevNet Resident
Posts: 1679 Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India
Post
by anjanesh » Tue Jan 10, 2006 5:33 am
Code: Select all
$contents = @file_get_contents($url);
$Total_Size = strlen($contents);
Does $Total_Size equal to the size of the file in bytes ?
Thanks
anjanesh
DevNet Resident
Posts: 1679 Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India
Post
by anjanesh » Tue Jan 10, 2006 6:04 am
Code: Select all
<?php
$filename = 'http://google.com';
echo $filename . ': ' . filesize($filename) . ' bytes';
?>
filesize doesnt seem to accept urls.
But strlen seems to be the answer according to one
post .
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jan 10, 2006 9:09 am
strlen() is the byte count of the string given to it.
filesize() cannot read remote url's because it requires file system level access to the file.
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Tue Jan 10, 2006 10:09 am
feyd wrote: strlen() is the byte count of the string given to it
... if it hasn't been overloaded by
mbstring extension.
Maugrim_The_Reaper
DevNet Master
Posts: 2704 Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland
Post
by Maugrim_The_Reaper » Tue Jan 10, 2006 10:18 am
Returns the length of the given string.
Maybe they should make it clearer? I honestly hadn't considered it before now... Its almost automatic to assume it means the number of letter - not bytes. Which makes it interesting given the attached comments in relation to UTF-8.
Well, you learn something new everyday