-
Counting Files In Folder
Hey everyone,
Im working on this website with my brother for my cousin and to save my cousin some effort, I need to be able to count the number of files that are contained in a folder.
Im pretty sure it will require Php, so if anyone know how or of any tutorials, could you please point me in the right direction?
Many thanks :)
-
PHP Code:
<?php
//get path of directory containing this script
$dir = $_SERVER['DOCUMENT_ROOT'].dirname($PHP_SELF);
//open a handle to the directory
$handle = opendir($dir);
//intitialize our counter
$count = 0;
//loop through the directory
while (false !== ($file = readdir($handle))) {
//evaluate each entry, removing the . & .. entries
if (is_file($file) && $file !== '.' && $file !== '..') {
$count++;
}
}
echo $count;
?>
-
Hey it works, thanks alot Jason!
Is that possible to integrate with flash, or is it straight Php script.
-
I was trying to find out how to count the number of files in a folder (to use it with an image/video gallery), and I found this old thread.
Anyway, I've tried that script in my server, and for some reason it doesn't seem to work.
If I place the .php file in the root dir of my server, it always returns 0, no matter the number of files in there.
Then if I try to place it inside any other subfolder, I always get this:
Code:
Warning: opendir(//imagenes): failed to open dir: No such file or directory in /home/www/hoysesale.awardspace.com/imagenes/contador.php on line 5
Warning: readdir(): supplied argument is not a valid Directory resource in /home/www/hoysesale.awardspace.com/imagenes/contador.php on line 9
0
Could anyone give me a clue of what I need to do?
Thanks in advance
-
yeah use loadVars in flash to sendAndLoad to the php file given to u above... and echo out the variable from php as
echo &numberOfFiles=$count&;