Jump to content

Get number of files in a folder


Omirion

Recommended Posts

By using scandir built in function. Put the data from that into an array then counting the elements of the array.

<?php
$bob = scandir("images/");
$count = count($bob);
echo $count;
?> 

Of course you will want to sort out of the array the directory listing as well.

$bob = scandir("images/");
$count = count($bob);
for($i = 0; $i < $count; $i++) // Loops through $bob
   {
      if(is_file($bob[$i]))
      {
      	array_push($bob_2,bob[$i]); // adds an array element to $bob_2 only if not a folder and is a file
      }
   }

$count = count($bob_2);
echo $count;

http://www.w3schools.com/php/func_directory_scandir.asp

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.