Count Number of Files in a Directory / Folder – PHP

Hi Guys,
Today I share some useful topic related to two inbuilt function s in php for count number of files in php. The functions are:

  • glob(()
  • count()

Here’s a simple code of PHP code to get the total number of files in a directory using the glob() and count() function.



The first function to discuss is glob() it allows us to perform a search for pathnames using wildcards common to the best known shells.

The count function helps to count all files in specified directory.

count_folder



CODE





the Output will be

Total number Of files in a folder:4

We can count all the files in a folder and also count particular extension files(.jpeg / .php / .pdf etc)



The output will be:

Total number of php file in a folder :3



If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

3 thoughts on “Count Number of Files in a Directory / Folder – PHP

  1. bij nl

    Hi! Do you know if they make any plugins to help with
    Search Engine Optimization? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very
    good gains. If you know of any please share.
    Many thanks! You can read similar art here: Wool product

Leave a Reply

Your email address will not be published.