Jump to content

[SOLVED] Folder file size function


glenelkins

Recommended Posts

Hi

I am writing a function to check file sizes of files in folders of multiple levels. For example

Folder >
    Folder >
        Folder >
          Files
          Files
          Files
        Folder >
          Files
        Files
        Files
        Files

here 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 21


Warning: readdir(): supplied argument is not a valid Directory resource in f:\data\gedev\www\gepanel\account.php on line 8

Warning: fclose(): supplied argument is not a valid stream resource in f:\data\gedev\www\gepanel\account.php on line 21


any ideas??
Link to comment
https://forums.phpfreaks.com/topic/31669-solved-folder-file-size-function/
Share on other sites

Hi

m 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
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.