PHP - Bring weight of each file / file in a cycle

0

Good morning. I need to bring the weight of each of the files (they are all images) that are inside a directory.

<?php
    $directorio = "vistas/img/productos";
    $scandir  = scandir($directorio, 1);
?>

<div class="container">
    <div class="col-12">
        <ul>
            <?php
                foreach($scandir as $key => $value){
                    echo '
                        <li>
                            '.$value.' - '.filesize($value).'
                        </li>'
                    ;
                }

                // anda bien si tomo un archivo o carpeta, pero no cuando hago el ciclo
                echo '<span>File Size: '.filesize($directorio).'</span>'
            ?>
        </ul>
    </div>
</div>

If I remove the filesize it brings me all the files, that is, a list with the name of each one including its extension. The problem is that when trying to apply filesize to the value (to each result that the cycle brings me) then I get next to each file name:

Warning: filesize (): stat failed for (and here the name of the image)

What am I missing?

    
asked by Franco Nicolas Vega 25.12.2018 в 12:27
source

1 answer

0

You should concatenate $ value with $ directory and with the '/'.

I leave the cycle:

foreach($scandir as $key => $value)
{
    echo '<li>' . $value. ' - ' . filesize($directorio . '/' . $value) . '</li>';
}
    
answered by 25.12.2018 / 13:09
source