carly31
3/10/2016 - 3:42 AM

Count files in a folder

Count files in a folder

// integer starts at 0 before counting
$i = 0; 
$dir = 'hello/';

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 are $i files in <a href='hello'>$dir</a> directory";