If you are just counting the files in the current directory (and not recursing to sub-directories), then it's easy! 🙂
$dir = readdir("mydir");
while ($file = opendir($dir)) {
if ($file != "." && $file != ".." && !is_dir("mydir/$file"))
$num_files++;
}
Or better yet, if you're on a Linux box
$files = explode("\n", shell_exec("ls -1"));
$num_files = (count($files) - 1);
(Note, above code is ls -1 where "-1" is the number ONE, NOT a lowercase "L")
If you want to read all of the files in the directory and its sub-directories, you'll need to write a recursive function for that.
The pseudo code routine would be something like this:
function listFilesInDir {
global $num_files
$file = list_files_in_dir
if (is_dir)
listFilesInDir
else
$num_files++;
}