glenelkins Posted December 23, 2006 Share Posted December 23, 2006 HiI am writing a function to check file sizes of files in folders of multiple levels. For exampleFolder > Folder > Folder > Files Files Files Folder > Files Files Files Fileshere is the code[code]$used_quota = 0;function UsedQuota($base_folder,$folder_count) { global $used_quota; $open_dir = opendir($base_folder); while ($f = readdir($open_dir)) { if ($f != "." && $f != "..") { // If its a file take the size if (is_dir($base_folder . $f)) { // Is folder $folders[$folder_count] = $base_folder . $f . "/"; $folder_count++; } else { $used_quota = $used_quota + filesize($base_folder . $f); } } } fclose($open_dir); if ($folder_count > 0) { for ($i=0;$i<count($folders);$i++) { echo $folders[$i] . "<br>"; UsedQuota ($folders[$i],$folder_count); } }}[/code]I am getting the following errors:Warning: fclose(): supplied argument is not a valid stream resource in f:\data\gedev\www\gepanel\account.php on line 21Warning: readdir(): supplied argument is not a valid Directory resource in f:\data\gedev\www\gepanel\account.php on line 8Warning: fclose(): supplied argument is not a valid stream resource in f:\data\gedev\www\gepanel\account.php on line 21any ideas?? Link to comment https://forums.phpfreaks.com/topic/31669-solved-folder-file-size-function/ Share on other sites More sharing options...
redarrow Posted December 23, 2006 Share Posted December 23, 2006 i have read all and i think your not pointing to the correct folders please cheek and also use the full url ok. Link to comment https://forums.phpfreaks.com/topic/31669-solved-folder-file-size-function/#findComment-146814 Share on other sites More sharing options...
glenelkins Posted December 23, 2006 Author Share Posted December 23, 2006 Him sure I am trapping the folder names correctly using: $base_folder . $f Im not sure if it has something to do with the for loop, maybe it should be <=count( rather tha <count( i will try and let you know Link to comment https://forums.phpfreaks.com/topic/31669-solved-folder-file-size-function/#findComment-146815 Share on other sites More sharing options...
glenelkins Posted December 24, 2006 Author Share Posted December 24, 2006 sorted![code]$used_quota = 0;function UsedQuota($base_folder) { global $used_quota; $folder_count = 0; $open_dir = opendir($base_folder); // Go through files while ($f = readdir($open_dir)) { if ($f != "." && $f != "..") { if (is_dir($base_folder . $f)) { $folders[$folder_count] = $base_folder . $f . "/"; $folder_count++; } else { $used_quota = $used_quota + filesize($base_folder . $f); } } } if ($folder_count > 0) { for ($i=0;$i<count($folders);$i++) { UsedQuota($folders[$i]); } }}[/code] Link to comment https://forums.phpfreaks.com/topic/31669-solved-folder-file-size-function/#findComment-147269 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.