Posted By

gdonald on 09/27/06


Tagged

file size


Versions (?)

Who likes this?

8 people have marked this snippet as a favorite

luxuryluke
vaaaska
vali29
hudge
skywalker
MoFu
haozi
sbcjr


php file size


 / Published in: PHP
 

  1. $file_name = "/path/to/file";
  2.  
  3. $file_type = array( 'K', 'M', 'G' );
  4.  
  5. $size = filesize ( $file_name );
  6.  
  7. for ( $t = 0; $size > 1024; $t++ )
  8. {
  9. $size /= 1024;
  10.  
  11. $file_size = round ( $size, 1 ) . ' ' . $file_type[ $t ] . 'B';
  12. }
  13.  
  14. echo "\$file_size = $file_size";

Report this snippet  

You need to login to post a comment.