Welcome to Geeklog, Anonymous Wednesday, November 27 2024 @ 11:31 am EST

Geeklog Forums

file & folder size reporting block help needed


shift

Anonymous
Hi, I have a small php script that you drop in the root dir and when accessed by URL, reports the file / folder size of everything from the root down.
How would I create a block that runs the php script from its location in root, and shows the output in the block. Any ideas?
 Quote

Status: offline

ScurvyDawg

Forum User
Full Member
Registered: 11/06/02
Posts: 523
Move the function into your lib-custom and call to it as a PHP block??

 Quote

Shift

Anonymous
ERROR

Matching CODE tag missing. Unable to format message.

 Quote

Status: offline

ScurvyDawg

Forum User
Full Member
Registered: 11/06/02
Posts: 523
And from this we are supposed to guess at what the error in the code is?

maybe showing the code or being a little more clear may help you in garnering an answer.

Giving it a try
 Quote

shift

Anonymous
ops looked ok in preview.
Ok, I have very little php understanding so below is the code (not mine), do I paste it all into lib-custom?
Text Formatted Code
<?php
function DirStat($directory) {
        global $FolderCount, $FileCount, $FolderSize;

        chdir($directory);
        $directory = getcwd();
        if($open = opendir($directory)) {
                while($file = readdir($open)) {
                        if($file == '..' || $file == '.') continue;
                        if(is_file($file)) {
                                $FileCount++;
                                $FolderSize += filesize($file);
                        } elseif(is_dir($file)) {
                                $FolderCount++;
                        }
                }
                if($FolderCount > 0) {
                        $open2 = opendir($directory);
                        while($folders = readdir($open2)) {
                                $folder = $directory.'/'.$folders;
                                if($folders == '..' || $folders == '.') continue;
                                if(is_dir($folder)) {
                                        DirStat($folder);
                                }
                        }
                        closedir($open2);
                }
                closedir($open);
        }
}

function ByteSize($bytes) {
        $size = $bytes / 1024;
        if($size < 1024){
                $size = number_format($size, 2);
                $size .= 'kb';
        } else {
                if($size / 1024 < 1024) {
                        $size = number_format($size / 1024, 2);
                        $size .= 'mb';
                } elseif($size / 1024 / 1024 < 1024) {
                        $size = number_format($size / 1024 / 1024, 2);
                        $size .= 'gb';
                } else {
                        $size = number_format($size / 1024 / 1024 / 1024, 2);
                        $size .= 'tb';
                }
        }
        return $size;
}

$folder = 'FolderName';
$dir = getcwd();
DirStat($folder, 0);
chdir($dir);
$FolderSize = ByteSize($FolderSize);

echo '<b>Folder Name:</b> '.$folder.''.chr(10);
echo '<b>File Count:</b> '.$FileCount.''.chr(10);
echo '<b>Folder Size:</b>'.$FolderSize.''.chr(10);
?>
 
 Quote

shift

Anonymous
OK, I have worked out that if I put the code below into lib-common my script runs in a block.
Text Formatted Code
function phpblock_gallerysize() {
    $content = file_get_contents('foldersize.php');
    return $content;
}
 

I would like to make it more geeklog intergrated by changing the 2nd line down to something like
Text Formatted Code
$content = file_get_contents( $_CONF['site_url'] . '/foldersize.php');
 

using the $_CONF ['site_url'] that is created in config.php
But when I try this it creates a block with the static text but not the file sizes.
I am really trying to get to grips with GL & PHP and would be very thankful for any help. Banging your head
 Quote

All times are EST. The time is now 11:31 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content