PHP: How to count files in folder?By Hardik Savani | February 4, 2016 | | 1271 Viewer | Category : PHP
Share this post:
In PHP, you are work on php and you want to need display count number of files in specific folder then you do, glob() through you count number of file are there in specified folder. now in following example you can see "/var/www/test" in this folder, count how many files are there in that folder. glob function take a two argument first one for directory or folder path and second argument for filter. Filter means if you pass '*' then it will count all type of file, i mean all extension, but if you need to count just text file then you can put like '*.txt'.
That't it, if in your directory, function does not find any file then it will always return "false". you can check following example and try that...
$folderPath = '/var/www/test';
$file = glob($folderPath . '*');
$countFile = 0;
if ($file != false)
$countFile = count($file);
- Laravel 5.2 chat message module using socket.io, redis, express and nodejs from from scratch.
- Laravel 5.4 New Feature - Add new Components & Slots in Blade Template
- How to create laravel 5 widgets ?
- How to add jquery modal popup in PHP?
- Laravel 5 generate sitemap using roumen/sitemap package Example
- How to create custom facade in laravel 5.2?
- Codeigniter 3 and AngularJS CRUD with Search and Pagination Example.
- How to create Pagination using dirPagination directive in Angularjs example with demo ?