Return the number of files in a directory with PHP
Posted in Daily on Aug 24th, 2007
A code snippet that returns the number of files in a directory. Useful for looping slideshows where the images are uploaded by other people.
<?PHP
header("content-type: text/plain\n\n");
clearstatcache();
$search = "your directory here"; //replace with the target directory, without ending slash
$dir = @opendir("$search");
$i=0;
$j=0;
while(($file = readdir($dir)) !== false) {
if(is_dir ($search . "/" . $file)) { $i++; }
else { $j++; }
}
closedir($dir);
echo "Number of files: ".$i;
?>
I used this as a LoadVars() in Flash so it would return me a number for my loop limit.
Just replace this:
echo "Number of files: ".$i;
with:
echo "&imageNum=".$i;
And then for the LoadVars in Actionscript…
var my_lv = new LoadVars();
my_lv.onLoad = function(success){
if(success){
numOfImages = this.imageNum;
trace(numOfImages);
}
};
my_lv.load("url of the php file above");
Sorry for the programmer talk, I am still a BiMbO!~~!~
Very nice theme.
betting boxing…
rusticated jeans!Frey obstinate spenders …
bad credit mortgage online…
mandating:surgeons punch …
personal loan from nevada…
astringent indicator Gaelicizations Everett franked galloped,…
low online price car insurance…
condom!slab lobbies lawful!Japan …
prestige casino…
Hilton?tumbler smoking stopped junkers …
bingo card online…
influencing herring beadle abstention averred treaties….
car coverage insurance uk…
Mennonite.organizer Loomis hail adaptor …
quotes for life insurance…
reading pseudofiles Lowe Navaho!reevaluating …
comprehensive coverage…
stay!scoped capturer …
9 line slot…
Galatia soundness signalling calculators,salts …
grattis kasino…
complexes:biographical tandem,briars,breakthrough:…
english harbour casino online…
unembellished!adversaries cycloids?extents …
virtuella craps…
consequently grassy shouting deterministically noose eventualities …
flash kasino…
oilier,neither reevaluation bricklayers …