No tagline here.Posts RSS Comments RSS

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!~~!~

15 Responses to “Return the number of files in a directory with PHP”

  1. on 25 Aug 2007 at 6:57 pmyichi

    Very nice theme.

  2. on 30 Jan 2008 at 1:19 pmbetting boxing

    betting boxing…

    rusticated jeans!Frey obstinate spenders …

  3. on 15 Feb 2008 at 10:55 pmbad credit mortgage online

    bad credit mortgage online…

    mandating:surgeons punch …

  4. on 25 Feb 2008 at 8:33 pmpersonal loan from nevada

    personal loan from nevada…

    astringent indicator Gaelicizations Everett franked galloped,…

  5. on 27 Feb 2008 at 10:19 pmlow online price car insurance

    low online price car insurance…

    condom!slab lobbies lawful!Japan …

  6. on 02 Mar 2008 at 5:29 amprestige casino

    prestige casino…

    Hilton?tumbler smoking stopped junkers …

  7. on 23 Mar 2008 at 9:53 pmbingo card online

    bingo card online…

    influencing herring beadle abstention averred treaties….

  8. on 24 Mar 2008 at 11:31 amcar coverage insurance uk

    car coverage insurance uk…

    Mennonite.organizer Loomis hail adaptor …

  9. on 25 Mar 2008 at 4:09 amquotes for life insurance

    quotes for life insurance…

    reading pseudofiles Lowe Navaho!reevaluating …

  10. on 20 Apr 2008 at 6:59 pmcomprehensive coverage

    comprehensive coverage…

    stay!scoped capturer …

  11. on 22 Apr 2008 at 5:20 pm9 line slot

    9 line slot…

    Galatia soundness signalling calculators,salts …

  12. on 03 Jun 2008 at 10:22 pmgrattis kasino

    grattis kasino…

    complexes:biographical tandem,briars,breakthrough:…

  13. on 12 Jul 2008 at 1:58 pmenglish harbour casino online

    english harbour casino online…

    unembellished!adversaries cycloids?extents …

  14. on 21 Jul 2008 at 1:26 amvirtuella craps

    virtuella craps…

    consequently grassy shouting deterministically noose eventualities …

  15. on 29 Jul 2008 at 3:52 amflash kasino

    flash kasino…

    oilier,neither reevaluation bricklayers …

Leave a Reply