Files
controls-web/lasuca/inc/dtrlistfunctions.php
2026-02-17 09:29:34 -06:00

99 lines
2.0 KiB
PHP

<?PHP
// phpcs:ignoreFile
//dirLIST v 0.1.1 functions file
function get_dir_content($path)
{
$content = array();
$dh = opendir($path);
while (false !== ($item = readdir($dh)))
{
array_push($content, $item);
}
return $content;
}
function folder_size($path)
{
global $listing_mode;
$total_size = 0;
if($listing_mode == 0) //HTTP
{
//determine operating system PHP is running on
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
{
$content = get_dir_content($path);
//remove . and ..
array_shift($content);
array_shift($content);
foreach($content as $key => $val)
{
$content_path = $path."/".$val;
if(is_dir($content_path))
{
$total_size += folder_size($content_path."/");
}
else
{
$total_size += filesize($content_path);
}
}
return ($total_size);
}
else
{
$folder_size = `du -s $path`;
$size_array = explode("\t", $folder_size);
return $size_array[0]*1024;
}
}
elseif($listing_mode == 1) //FTP
{
global $ftp_stream;
$dir_content = ftp_rawlist($ftp_stream, $path);
$ignore = array(".", "..");
foreach($dir_content as $key => $val)
{
$current = parse_rawurl($val);
if(substr($current[0], 0, 1) == "d" and !in_array($current[8], $ignore))
{
$dir_size = folder_size($path."/".$current[8]);
$total_size += $dir_size;
}
else
{
$total_size += $current[4];
}
}
return ($total_size);
}
}
function parse_rawurl($val)
{
$current = preg_split("/[\s]+/",$val,9);
return $current;
}
function letter_size($byte_size)
{
$file_size = $byte_size/1024;
if($file_size >= 1048576)
$file_size = sprintf("%01.2f", $file_size/1048576)." GB";
elseif ($file_size >= 1024)
$file_size = sprintf("%01.2f", $file_size/1024)." MB";
else
$file_size = sprintf("%01.1f", $file_size)." KB";
return $file_size;
}
function display_error_message($message)
{
return "
<table width=\"100%\" cellpadding=\"5\" cellspacing=\"1\" class=\"table_border\">
<tr><td bgcolor=\"#FFBBBD\">$message</td></tr>
</table>";
}
?>