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 ItSolutionstuff.com. 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
- Convert HTML to PDF in PHP with Dompdf Example
- How to Integrate Google Map using Gmaps JS?
- PHP Remove Duplicates from Multidimensional Array Example
- MySQL Query to Get Current Year Data Example
- How to Get File Name without Extension in PHP?
- How to Remove White Space from String in PHP?
- PHP Check Word Exist in String or Not Example
- How to Get a Current Page URL in PHP?
- How to Get php.ini File Path in Ubuntu?
- 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?