note 76084 deleted from function.filesize by aidan
| From: | aidan@php.net | Date: | Sat, 02 May 2009 11:17:46 +0000 |
| Subject: | note 76084 deleted from function.filesize by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154120@lists.php.net to get a copy of this message | ||
Note Submitter: BIZARREdotBG[at]GMAILdotCOM
----
Here is a simple addition to the original example that i have made.
First of all i must mention that i need to list all files in a dir and i do know all files names.
Because the filenames contains an INT at the same place in every file's name i use $n++ to
generate the file names.
The code:
<?php
// outputs e.g. bits_01.jpg: 0.05 kb
//lets asign a value of 1 so we can start with file bits_01.jpg
$n = 1;
//the last file is bits_09.jpg so i call the WHILE until $n gets a value of 9
while ($n < 10) {
//using $n in each file's name
$filename = 'bits_0'.$n.'.jpg';
//getting the file size - from original example
$size = filesize($filename);
//while i don't wan't the result in bytes instead i divide by 1024 to print it out in kilo
bytes (if you need it in MB then divide it by 1048576
//at the same line we round the result to the fourth sign after the comma
$sizemb = round(($size/1024),4);
//printing the result
//filename : size MB and brake to print next on the next line
echo $filename . ': ' . $sizemb . ' kb<br />';
//now after i've printed the first file and it's size, we proceed to the next one
$n++;
}
?>
Hope it is useful to someone.
P.S
Please excuse my bad English :-)