Home php How to count number of files in directory PHP?

How to count number of files in directory PHP?

by Shahriar Sagor

Today now in this blog i will show you how to count number of files in directory in php. If we are working on code php and we need to count the number of files, images, zip file, rar files, etc in the given folder path, then we can count by using glob() and count() of php. So, let’s start and see this bellow example and learn how it done.

$folderPath = "upload/";
$countFile = 0;
$totalFiles = glob($folderPath . "*");
if ($totalFiles){
 $countFile = count($totalFiles);
}
print_r($countFile);

Read Also : How to Create Custom Blade Directive in Laravel?

Thanks for read. I hope it help you. For more you can follow us on facebook.

close

You may also like