PHP function to count files in a directory on the server Simple PHP function to count files in a directory on the server, how to count files in a directory with php.
For this we use $_SERVER['DOCUMENT_ROOT'], glob() and count()
The glob() function searches for all the pathnames matching pattern according to the rules used by the libc glob() function, which is similar to the rules used by common shells.
Description int count ( mixed $var [, int $mode ] )
Returns the number of elements in var , which is typically an array, since anything else will have one element.
For objects, if you have SPL installed, you can hook into count() by implementing interface Countable. The interface has exactly one method, count(), which returns the return value for the count() function.
If var is not an array or an object with implemented Countable interface, 1 will be returned. There is one exception, if var is NULL, 0 will be returned.
Depending on which file names you need to count, replace "*" with what ever suits your needs.
Go to Glob function on php.net website to see what other modifications you can do to it.
The bluehost and the globat hosting services are offering the best website development programs. The cfml language is converted by the hosts to the readable language for the human understanding. The cingular wireless is offering cheap and affordable rates to their users to make calls. The midphase hosting companies are offering python language programming software at cheap rates.
Hello, Guest ! You can Login or Register to www.ivorde.ro!
Post comment:
2 comment(s) to PHP function to count files in a directory on the server:
1. Re: PHP function to count files in a directory on the server
Re: you're missing a parenthesis by admin
at June 21st, 2009 - 06:29
Modified. Thanks.
2. Re: PHP function to count files in a directory on the server
d by ion
at March 13th, 2009 - 10:16
you're missing a parenthesis this -> $count = count(glob($_SERVER['DOCUMENT_ROOT'].$dir . "*") ; should be ->$count = count(glob($_SERVER['DOCUMENT_ROOT'].$dir . "*") );
Designed and developed by Andrei Manescu. Optimized for Mozilla Firefox.
Copyright 2007 Andrei Manescu
All trademarks and copyrights on this page are owned by their respective owners. Comments are owned by those who posted them.