PHP filesize (decimal places) hep!

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

Post Reply
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

PHP filesize (decimal places) hep!

Post by gotDNS »

Hey, how do i use filesize() so that it only shows the file size out to 2 decimal places? PHP.net seems to be down, so anyone that can help, thanks!
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

$f_size1 = filesize($file_name);
$f_size2 = substr($f_size1, 0, 4);


might work... and $f_size2 would be the filesize only to two decimal places...
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

sorry, that was totally wrong

$size = filesize($filename);
$size = ($size/1000);
$size = round($size,2);

will put it in KB, rounding to 2 decimal places
User avatar
sam
Forum Contributor
Posts: 217
Joined: Thu Apr 18, 2002 11:11 pm
Location: Northern California
Contact:

Post by sam »

Code: Select all

$size = ($size/1024);
Cheers Sam
Post Reply