php - how to count together the size of files when they are created in foreach loop -


i using folder in user can upload files. these files outputted name , size.

$dir = "users/$username"; $files = scandir($dir);  foreach ($files $file) { if ($file != '.' && $file != '..') { echo sizeformat(filesize($dir . '/' . $file)); } 

so output looks this:

koala.jpg => 600kb

jellyfish.jpg => 600kb

tulips.jpg => 500kb

how can count sizes together?

something like: toal size files: 1700kb

like this:

$dir = "users/$username"; $files = scandir($dir); $total = 0;  foreach ($files $file) {     if ($file != '.' && $file != '..') {         $total += filesize($dir . '/' . $file);         echo sizeformat(filesize($dir . '/' . $file));     } } echo $total; 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -