- fixed filesize() bug with files over 2GB for unix based systems, fix for windows on the todo list.

- added Size to file popup in Slik template

git-svn-id: file:///Users/jimeh/Desktop/dlist/trunk@35 a5845835-ea0f-0410-a762-dd0bfe9bfde8
This commit is contained in:
jim
2006-11-04 16:13:01 +00:00
parent 215b8e52da
commit cce99484cf
3 changed files with 45 additions and 13 deletions

View File

@@ -4,7 +4,7 @@ class dirList {
/* /*
Class: dirList v2.1.2 beta Class: dirList v2.2 beta
Copyright © 2006 Jim Myhrberg. Copyright © 2006 Jim Myhrberg.
zynode@gmail.com zynode@gmail.com
@@ -216,6 +216,7 @@ class dirList {
if ( is_file($item) ) { if ( is_file($item) ) {
$return['type'] = 'file'; $return['type'] = 'file';
$return['size_raw'] = filesize($item); $return['size_raw'] = filesize($item);
if ( $return['size_raw'] < 0 ) $return['size_raw'] = $this->get_large_filesize($item);
$return['size'] = $this->format_filesize($return['size_raw']); $return['size'] = $this->format_filesize($return['size_raw']);
} elseif ( is_dir($item) ) { } elseif ( is_dir($item) ) {
$return['type'] = 'dir'; $return['type'] = 'dir';
@@ -225,6 +226,32 @@ class dirList {
return $return; return $return;
} }
function get_large_filesize ($file) {
$system = $this->system_info();
if ( $system == 'unix' ) {
exec('ls -l "'.str_replace('"', '\"', $file).'"', $details, $result);
if ( $result == 0 ) {
foreach( $details as $key => $value ) {
preg_match('/.*?([0-9]{10,32}).*/i', $value, $size);
return (!empty($size[1])) ? $size[1] : 'LARGE' ;
}
} else {
return 'LARGE';
}
} else {
return 'LARGE';
}
}
function system_info () {
if ( stripos('windows', $_SERVER['SERVER_SOFTWARE']) ) {
return 'windows';
} else {
return 'unix';
}
}
function getOwner ($item) { function getOwner ($item) {
if ( function_exists('posix_getpwuid') ) { if ( function_exists('posix_getpwuid') ) {
$id = fileowner($item); $id = fileowner($item);
@@ -242,13 +269,17 @@ class dirList {
} }
function format_filesize($bytes) { function format_filesize($bytes) {
$types = array('bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); if ( $bytes !== 'LARGE' ) {
for($n = 0; $bytes >= 1024; $n++) $bytes = $bytes / 1024; $types = array('bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$bytes = number_format($bytes, 2); for($n = 0; $bytes >= 1024; $n++) $bytes = $bytes / 1024;
if ( preg_match("/^([0-9]+)(\.|,)([0-9]+0)$/", $bytes, $split) ) { $bytes = number_format($bytes, 2);
$bytes = ( ($split[3] = rtrim($split[3], '0')) == '' ) ? $split[1] : $split[1].$split[2].$split[3] ; if ( preg_match("/^([0-9]+)(\.|,)([0-9]+0)$/", $bytes, $split) ) {
$bytes = ( ($split[3] = rtrim($split[3], '0')) == '' ) ? $split[1] : $split[1].$split[2].$split[3] ;
}
return $bytes.' '.$types[$n];
} else {
return '>2 GB';
} }
return $bytes.' '.$types[$n];
} }
function smartDate ($timestamp, $datef='%B %d, %Y', $timef='%H:%M', $mainf='{date}, {time}') { function smartDate ($timestamp, $datef='%B %d, %Y', $timef='%H:%M', $mainf='{date}, {time}') {

View File

@@ -12,12 +12,13 @@
<a href="<?=rawurlencode($item['name'])?><? if($item['type'] == 'dir') echo '/'; ?>" onmouseover="iP(<?=$n.$thumbnail?>)" onmouseout="o()"> <a href="<?=rawurlencode($item['name'])?><? if($item['type'] == 'dir') echo '/'; ?>" onmouseover="iP(<?=$n.$thumbnail?>)" onmouseout="o()">
<span id="p<?=$n?>"><div class="name"><?=$item['name']?></div> <span id="p<?=$n?>"><div class="name"><?=$item['name']?></div>
<? <?
if ( !empty($fields['owner']) ) echo $lang->owner.': '.$item['owner'].'<br />'; if ( !empty($fields['size']) && $item['type'] == 'file' ) echo $lang->size.': '.$item['size'].' ('.number_format($item['size_raw']).' bytes)<br />';
if ( !empty($fields['group']) ) echo $lang->group.': '.$item['group'].'<br />';
if ( !empty($fields['perms']) ) echo $lang->perms.': '.$item['perms'].'<br />';
if ( !empty($fields['chmod']) ) echo $lang->chmod.': '.$item['chmod'].'<br />';
if ( !empty($fields['mtime']) && $item['type'] == 'file' ) echo $lang->mtime.': '.$item['mtime'].'<br />'; if ( !empty($fields['mtime']) && $item['type'] == 'file' ) echo $lang->mtime.': '.$item['mtime'].'<br />';
if ( !empty($fields['atime']) ) echo $lang->atime.': '.$item['atime'].'<br />'; if ( !empty($fields['atime']) ) echo $lang->atime.': '.$item['atime'].'<br />';
if ( !empty($fields['perms']) ) echo $lang->perms.': '.$item['perms'].'<br />';
if ( !empty($fields['chmod']) ) echo $lang->chmod.': '.$item['chmod'].'<br />';
if ( !empty($fields['owner']) ) echo $lang->owner.': '.$item['owner'].'<br />';
if ( !empty($fields['group']) ) echo $lang->group.': '.$item['group'].'<br />';
if ( !empty($fields['owner_id']) ) echo $lang->owner_id.': '.$item['owner_id'].'<br />'; if ( !empty($fields['owner_id']) ) echo $lang->owner_id.': '.$item['owner_id'].'<br />';
if ( !empty($fields['group_id']) ) echo $lang->group_id.': '.$item['group_id'].'<br />'; if ( !empty($fields['group_id']) ) echo $lang->group_id.': '.$item['group_id'].'<br />';
?> ?>

View File

@@ -101,8 +101,8 @@
</div> </div>
</div> </div>
<div id="icons-view" style="display: ;"><? if ($include_icons) include($config->tpl_icons_file); ?></div> <div id="icons-view"<? if (!$include_icons): ?> style="display: none;"<? endif; ?>><? if ($include_icons) include($config->tpl_icons_file); ?></div>
<div id="details-view" style="display: none;"><? if ($include_details) include($config->tpl_details_file); ?></div> <div id="details-view"<? if (!$include_details): ?> style="display: none;"<? endif; ?>><? if ($include_details) include($config->tpl_details_file); ?></div>
<img src="<?=TPL_URL?>images/spacer.gif" width="100%" height="1" alt="Spacer" /> <img src="<?=TPL_URL?>images/spacer.gif" width="100%" height="1" alt="Spacer" />