How to count number of files in directory PHP?

By Hardik Savani | March 14, 2016 | | 35207 Viewer | Category : PHP


If you are working on code php and you require to count number of files, images, zip file, rar files, etc in the given folder path, then you can count using glob() and count() of php. So, let's see this bellow example and learn how it done.

$folderPath = "upload/";

$countFile = 0;

$totalFiles = glob($folderPath . "*");

if ($totalFiles){

$countFile = count($totalFiles);

}

print_r($countFile);



Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.