Tried this earlier but have had no takers....is it a no go? Please read on.
Hello! I hope someone can help me with this...it's doin' my head in! Below I have a class I found for finding out directory sizes. What I have done is to get the username of each user and their create a directory path (based on their username - these directories do exist with subdirs). This works fine when I restrict the select statement to 1 user, but when selecting all, it generates an error for (nearly) all the users, namely, the ones with no contents in their directories. Thing is, just above the error, it prints what I want ( I think - haven't check it for accuracy yet). Any help or ideas on how to achieve this would be most helpful and appreciated!! (Win2K, PHP 4.1.1) The Code ----------------------------------------------- <?php include "../../conf/dbinfo.php"; ?> <?php class DirectoryInfo { //recursively gets the size of a directory. function get_dir_size($dir, &$size) { if (isset($handle)) { $handle = ""; } $handle = opendir($dir); if(!$handle ) { return $this->display_size(0); } else { while( $file = readdir($handle) ) { if($file != '.' and $file != '..') { is_dir("$dir/$file") ? $this->get_dir_size("$dir/$file", $size) : $size += filesize("$dir/$file"); } } if ($size < 1) { return $this->display_size(0); $handle =""; $size = "0"; } else { return $this->display_size($size); $handle =""; $size = "0"; } } } // File size calculations - for display. function display_size($file_size) { if($file_size >= 1073741824) { $file_size = round($file_size / 1073741824 * 100) / 100 . " Gb"; } elseif($file_size >= 1048576) { $file_size = round($file_size / 1048576 * 100) / 100 . " Mb"; } elseif($file_size >= 1024) { $file_size = round($file_size / 1024 * 100) / 100 . " Kb"; } else { $file_size = $file_size . " bytes"; } return $file_size; } } $sql = "SELECT * FROM FTPUsers"; $result = $dsn2->query( $sql ); if ( DB::isError( $result = $dsn2->query( $sql ) ) ) { echo DB::errorMessage( $result ); } else { while ( $row = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) { $dir = "F:/path/to/" . $row[Name] . ""; $d = new DirectoryInfo; echo "<P>" . $row[Name] . " " . $d->get_dir_size($dir, $size); } } ?> ----------------------------------------------- Result ----------------------------------------------- User1 0 bytes Warning: OpenDir: Invalid argument (errno 22) in F:\OBS\WinPartnerWeb\www\partners\pa\obsWebsite\testsize.php on line 13 User2 0 bytes Warning: OpenDir: Invalid argument (errno 22) in F:\OBS\WinPartnerWeb\www\partners\pa\obsWebsite\testsize.php on line 13 User3 0 bytes User4 26.33 Mb Warning: OpenDir: Invalid argument (errno 22) in F:\OBS\WinPartnerWeb\www\partners\pa\obsWebsite\testsize.php on line 13 User5 0 bytes Warning: OpenDir: Invalid argument (errno 22) in F:\OBS\WinPartnerWeb\www\partners\pa\obsWebsite\testsize.php on line 13 User6 0 bytes Warning: OpenDir: Invalid argument (errno 22) in F:\OBS\WinPartnerWeb\www\partners\pa\obsWebsite\testsize.php on line 13 ... ----------------------------------------------- Thanks Simon H -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php