wordpress_add

Tuesday 19 November 2013

Count files in any directory using php..!!

Dr-Wordpress : how to count the number of files in any directory using php.


<?php 
    //Counts starts at 0
    $i = 0; 
    $dir = 'images/Trip_images/';
    if ($handle = opendir($dir)) {
        while (($file = readdir($handle)) !== false){
            if (!in_array($file, array('.', '..')) && !is_dir($dir.$file)) 
                $i++;
        }
    }
    // print count files in directory
    echo "There were $i files";
?>


Subscribe Dr-Wordpress for Important Knowledge of wordpress..your's suggestions are most welcomed.

2 comments:

  1. Thanks Guys..!! Works great for me.

    ReplyDelete
  2. dr-wordpress...Really Nice..AweSome Dude

    ReplyDelete