Vivid Lust Posted November 30, 2007 Share Posted November 30, 2007 How could I account how many files there are in a directory and echo the amount? Thanks in advanced! Quote Link to comment Share on other sites More sharing options...
marcus Posted November 30, 2007 Share Posted November 30, 2007 <?php $count = count(glob("/path/to/your/directory/*")); # keep the asterick. echo $count; ?> Quote Link to comment Share on other sites More sharing options...
Vivid Lust Posted November 30, 2007 Author Share Posted November 30, 2007 It deosnt work ??? <?php $count = count(glob("http://imgsurf.freehostia.com/uploads/*")); # keep the asterick. echo $count; ?> http://imgsurf.freehostia.com/count.php Quote Link to comment Share on other sites More sharing options...
marcus Posted November 30, 2007 Share Posted November 30, 2007 Just do $count = count(glob("/uploads/*")); echo $count; Quote Link to comment Share on other sites More sharing options...
Vivid Lust Posted November 30, 2007 Author Share Posted November 30, 2007 still 0 ..... Quote Link to comment Share on other sites More sharing options...
Bramme Posted November 30, 2007 Share Posted November 30, 2007 are you sure the path is correct? else try with <?php $root = $_SERVER['DOCUMENT_ROOT']; $path= $root.'/uploads/'; $i = count(glob($path.'*')); echo $i; ?> Quote Link to comment Share on other sites More sharing options...
Tjazi Posted November 30, 2007 Share Posted November 30, 2007 It deosnt work ??? <?php $count = count(glob("http://imgsurf.freehostia.com/uploads/*")); # keep the asterick. echo $count; ?> http://imgsurf.freehostia.com/count.php I was going to say you'll need your full path, which you can find by placing a file in your "uploads" folder called, lets say for instance, testblah.php with the contents: <?php prin/*t "hi"; ?> That should give an error, the path of the error that it gives is your full path, minus the filename of the file. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted November 30, 2007 Share Posted November 30, 2007 <?php echo count(glob("uploads/*")); ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted November 30, 2007 Share Posted November 30, 2007 If you wanted to count the number of files in a particular folder and all sub folders, you'd need to use recursion. Here's a blue peter-esque one i made earlier <?php function no_of_files($dir){ $no_of_files=0; $handler = opendir($dir); while(false !== ($file = readdir($handler))){ if($file != '.' && $file != '..'){ if(is_dir($dir.'\\'.$file)){//if this is a directory, recall the function with the subdirectory defined $sub_dir = $dir.'\\'.$file; $no_of_files += no_of_files($sub_dir); }else{//is a file, so increase our counter $no_of_files++; } } } return $no_of_files; } echo no_of_files('C:\Documents and Settings\Ben\My Documents\My Music'); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.