1
count files in folder
CGuild1.com > Tips & Tricks > count files in folder

Count files in a directory with PHP

Learn how to make count the amount of files in a directory with php.

<?php // integer starts at 0 before counting
    $i = 0;
    $dir = '../vehicle-images/';
    if ($handle = opendir($dir)) {
        while (($file = readdir($handle)) !== false){
            if (!in_array($file, array('.', '..')) && !is_dir($dir.$file))
                $i++;
        }
    }
    // prints out how many were in the directory
    echo "There were $i files";
?>


I found this over here at Stackoverflow.
©2024 CGuild1.com