php count files in directory – How to count files in a directory using PHP?

php count files in directory – PHP – Count the number of files in a Directory / folder. Also you can learn to List files and directories inside the images directory:

php count files in directory

PHP contains many functions like count(), iterator_count(), glob(), openddir(), readdir(), scandir(). Below is a function that count the number of files (and/or folder) in a folder or directory.

Also Read This πŸ‘‰   php download file - How to Download a File in PHP?

$fi = new FilesystemIterator(__DIR__, FilesystemIterator::SKIP_DOTS);
printf("There were %d Files", iterator_count($fi));

Count how many files in directory PHP

< ?php
function countFolder($dir) {
	return (count(scandir($dir)) - 2);

PHP: How to count files in folder?

$folderPath = '/var/www/test';
$file = glob($folderPath . '*');
$countFile = 0;
if ($file != false)
    $countFile = count($file);

echo countFolder('/var/pakainfo');

Free Live Chat for Any Issue

Don’t Miss : Count How Many Files In Directory PHP

echo (count(scandir('/var/pakainfo')) - 2);

I hope you get an idea about php count files in directory – How to count folder files using php?.
I would like to have feedback on my
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.