view raw
Jack Maessen Jack Maessen - 1 year ago 43
PHP Question

how to get the filesize of files in a foreach loop

I am trying to echo the filesize of all files in a directory but it doesn't echo the filesize, only the filename. This is my code:

$dir = "users/$UserName";
$files = scandir($dir);

echo '<table>';
foreach ($files as $file) {
if ($file != '.' && $file != '..') {

<td><?php echo $file."<br />";
<?php echo filesize($file);




what i am doing wrong?


AS m_poorUser said you need to pass the full file path to the filesize() function, maybe if you do this:

<?php echo filesize($dir."/".$file); ?>