extrovertive Posted August 9, 2006 Share Posted August 9, 2006 I'm writing a script that allows user to upload their pics to a folder (each user has his/her own folder). That folder will contain only pics. Now, I want it so that I can count the number of files are in the folder. Is there a function for this? Sort of like count() but for directory? Quote Link to comment Share on other sites More sharing options...
kalivos Posted August 9, 2006 Share Posted August 9, 2006 $dir = '/dir'; //folder to scan$files = scandir($dir); //scans the folder$count_of_files = count($files) - 2; // - 2 to account for "." and ".."*edit*This is for PHP5. What version are you running? Quote Link to comment Share on other sites More sharing options...
extrovertive Posted August 9, 2006 Author Share Posted August 9, 2006 PHP 4I'm only using PHP 4 since my client's webhost does not support PHP 5. Quote Link to comment Share on other sites More sharing options...
kalivos Posted August 10, 2006 Share Posted August 10, 2006 PHP 4 version$dir = "/dir";$dh = opendir($dir);while (false !== ($filename = readdir($dh))) { $files[] = $filename;}print_r($files); Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted August 10, 2006 Share Posted August 10, 2006 If you're running version 4.3 or higher, take a look at the glob() function http://www.php.net/glob[code]<?phpecho count(glob('/dir/*'));?>[/code]Ken 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.