How to Count Number of Files in Directory using PHP?
Hey Dev,
In this post, we will learn count number of files in directory php. you can see count number of files in folder php. you'll learn count number of images in folder php. It's a simple example of count number of images in a directory php. Let's see below example php count number of files in directory.
If you are working on code php and you require to count a number of files, images, zip files, rar files, etc in the given folder path, then you can count using glob() and count() of PHP. So, let's see the below example and learn how it did.
Example:
index.php
<?php
$folderPath = "upload/";
$countFile = 0;
$totalFiles = glob($folderPath . "*");
if ($totalFiles){
$countFile = count($totalFiles);
}
print_r($countFile);
?>
Output:
10
I hope it can help you...

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, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- PHP - How to convert HTML file to PDF using Dompdf library?
- How to integrate google map using gmaps.js in php example?
- PHP - How to remove duplicate values from multidimensional array?
- How to get current year rows using MySql Query PHP?
- How to get filename without extension in PHP?
- How to remove white space from string in PHP?
- How to check word exist in string or not in PHP?
- How to get current page url in PHP?
- How to get php.ini file path?
- How to Convert Array Values to Lowercase in PHP?
- How to Get Maximum Key Value of Array in PHP?
- How to Get Minimum Key Value of Array in PHP?
- How to Get Product using Rakuten Marketing API in PHP?
- How to Remove Null Values from Array in PHP?