PDA

View Full Version : Displaying number of files in a remote folder



7
19-06-2008, 12:51 PM
Anyone know of any scripts to show on a page how many files are in a certain folder?

Excellent
19-06-2008, 12:52 PM
What do you mean, as in cPanel or just an index?

7
19-06-2008, 12:55 PM
just a folder, for example i wanted to display how many files had been uploded into the uploads folder

Dentafrice
19-06-2008, 12:55 PM
Here's a code from my TehUpload core.



/**
* Numbers files in a directory
*
* @param string $dir
* @param boolean $recursive
* @param integer $counter
* @return integer
*/
public function numFiles ( $dir, $recursive = false, $counter = 0 )
{
static $counter;
if ( is_dir( $dir ) ) {
if ( $dh = opendir( $dir ) ) {
while ( ( $file = readdir( $dh ) ) !== false ) {
if ( $file != "." && $file != ".." ) {
$counter = ( is_dir( $dir . "/" . $file ) ) ? num_files( $dir . "/" . $file, $recursive, $counter ) : $counter + 1;
}
}
closedir( $dh );
}
}
return $counter;
}
Usage:



echo $core->numFiles('images/');
That is if it is in a class.



echo numFiles('images/');
You'll need to remove public for it to work out of PHP5 and a class.

7
24-06-2008, 03:04 PM
still havent found any that actually work

Dentafrice
24-06-2008, 03:14 PM
That works perfect..

7
24-06-2008, 03:28 PM
didnt for me

Dentafrice
24-06-2008, 03:29 PM
did it error?

Want to hide these adverts? Register an account for free!