Jump to content

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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.