Sahed
Sahed

Reputation: 25

how to get each file size individually from directory PHP

can anyone help me to get each file size individually from a local directory ?.

 $files = scandir('soft');    
foreach($files as $file) {
    echo $file . "<br />";

}

Upvotes: 2

Views: 3257

Answers (3)

Paul Bele
Paul Bele

Reputation: 1534

From here

 $files = scandir('soft');    
foreach($files as $file) {
 if (!in_array($file,array(".",".."))) 
  { 
    echo $file . "<br />";
    echo filesize('soft/'.$file) . ' bytes';
  }
}

Just need to keep in mind that scandir gets only the filenames in that dir, and not the relative path to it. that's why you need to use 'soft/'.$file and not $file

Upvotes: 3

PravinS
PravinS

Reputation: 2594

use filesize($filename) php function, it will give size in bytes

Upvotes: 0

Curtis W
Curtis W

Reputation: 511

<?
$files = scandir('.');
foreach($files as $file) {
  echo filesize($file) . " bytes<br>";
}
?>

Upvotes: 1

Related Questions