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? Link to comment https://forums.phpfreaks.com/topic/17076-counting-number-of-files-in-a-folder/ 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? Link to comment https://forums.phpfreaks.com/topic/17076-counting-number-of-files-in-a-folder/#findComment-72093 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. Link to comment https://forums.phpfreaks.com/topic/17076-counting-number-of-files-in-a-folder/#findComment-72116 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); Link to comment https://forums.phpfreaks.com/topic/17076-counting-number-of-files-in-a-folder/#findComment-72582 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 Link to comment https://forums.phpfreaks.com/topic/17076-counting-number-of-files-in-a-folder/#findComment-72593 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.