ItSolutionStuff.com

How to Count Number of Files in Directory using PHP?

By Hardik Savani • May 14, 2024
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...

Tags: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Convert HTML to PDF in PHP with Dompdf Example

Read Now →

How to Integrate Google Map using Gmaps JS?

Read Now →

PHP Remove Duplicates from Multidimensional Array Example

Read Now →

MySQL Query to Get Current Year Data Example

Read Now →

How to Get File Name without Extension in PHP?

Read Now →

How to Remove White Space from String in PHP?

Read Now →

PHP Check Word Exist in String or Not Example

Read Now →

How to Get a Current Page URL in PHP?

Read Now →

How to Get php.ini File Path in Ubuntu?

Read Now →

How to Convert Array Values to Lowercase in PHP?

Read Now →

How to Get Maximum Key Value of Array in PHP?

Read Now →

How to Get Minimum Key Value of Array in PHP?

Read Now →

How to Get Product using Rakuten Marketing API in PHP?

Read Now →

How to Remove Null Values from Array in PHP?

Read Now →