Count how many files in directory PHP
You can simply do the following :
$fi = new FilesystemIterator(__DIR__, FilesystemIterator::SKIP_DOTS);
printf("There were %d Files", iterator_count($fi));
You can get the filecount like so:
$directory = "/path/to/dir/";
$filecount = count(glob($directory . "*"));
echo "There were $filecount files";
where the "*"
is you can change that to a specific filetype if you want like "*.jpg"
or you could do multiple filetypes like this:
glob($directory . "*.{jpg,png,gif}",GLOB_BRACE)
the GLOB_BRACE
flag expands {a,b,c} to match 'a', 'b', or 'c'
Note that
glob()
skips Linux hidden files, or all files whose names are starting from a dot, i.e..htaccess
.