Format the file size, limits to Mb.
public formatSize ( integer $size ) : string | ||
$size | integer | the raw filesize |
return | string | formated file size. |
/** * Draw the files in an table. */ function drawFiles($list, &$manager) { global $relative; foreach ($list as $entry => $file) { ?> <td><table width="100" cellpadding="0" cellspacing="0"><tr><td class="block"> <a href="javascript:;" onclick="selectImage('<?php echo $file['relative']; ?> ', '<?php echo $entry; ?> ', <?php echo $file['image'][0]; ?> , <?php echo $file['image'][1]; ?> );"title="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?> "><img src="<?php echo $manager->getThumbnail($file['relative']); ?> " alt="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?> "/></a> </td></tr><tr><td class="edit"> <a href="images.php?dir=<?php echo $relative; ?> &delf=<?php echo rawurlencode($file['relative']); ?> " title="Trash" onclick="return confirmDeleteFile('<?php echo $entry; ?> ');"><img src="img/edit_trash.gif" height="15" width="15" alt="Trash"/></a><a href="javascript:;" title="Edit" onclick="editImage('<?php echo rawurlencode($file['relative']); ?> ');"><img src="img/edit_pencil.gif" height="15" width="15" alt="Edit"/></a> <?php if ($file['image']) { echo $file['image'][0] . 'x' . $file['image'][1]; } else { echo $entry; } ?> </td></tr></table></td> <?php } //foreach }
/** * Draw the files in an table. */ function drawFiles($list, &$manager) { global $relative; global $IMConfig; switch ($IMConfig['ViewMode']) { case 'details': ?> <script language="Javascript"> <!-- function showPreview(f_url) { window.parent.document.getElementById('f_preview').src = window.parent._backend_url + '__function=thumbs&img=' + f_url; } //--> </script> <table class="listview"> <thead> <tr><th>Name</th><th>Filesize</th><th>Dimensions</th></tr></thead> <tbody> <?php foreach ($list as $entry => $file) { ?> <tr> <th><a href="#" class="thumb" style="cursor: pointer;" onclick="selectImage('<?php echo $file['relative']; ?> ', '<?php echo $entry; ?> ', <?php echo $file['image'][0]; ?> , <?php echo $file['image'][1]; ?> );return false;" title="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?> " onmouseover="showPreview('<?php echo $file['relative']; ?> ')" onmouseout="showPreview(window.parent.document.getElementById('f_url').value)" ><?php echo $entry; ?> </a></th> <td><?php echo Files::formatSize($file['stat']['size']); ?> </td> <td><?php if ($file['image']) { echo $file['image'][0] . 'x' . $file['image'][1]; } ?> <td class="actions"> <a href="<?php print $IMConfig['backend_url']; ?> __function=images&dir=<?php echo $relative; ?> &delf=<?php echo rawurlencode($file['relative']); ?> " title="Trash" onclick="return confirmDeleteFile('<?php echo $entry; ?> ');"><img src="<?php print $IMConfig['base_url']; ?> img/edit_trash.gif" height="15" width="15" alt="Trash" border="0" /></a> <a href="javascript:;" title="Edit" onclick="editImage('<?php echo rawurlencode($file['relative']); ?> ');"><img src="<?php print $IMConfig['base_url']; ?> img/edit_pencil.gif" height="15" width="15" alt="Edit" border="0" /></a> </td> </tr> <?php } ?> </tbody> </table> <?php break; case 'thumbs': default: foreach ($list as $entry => $file) { ?> <div class="thumb_holder" id="holder_<?php echo asc2hex($entry); ?> "> <a href="#" class="thumb" style="cursor: pointer;" onclick="selectImage('<?php echo $file['relative']; ?> ', '<?php echo $entry; ?> ', <?php echo $file['image'][0]; ?> , <?php echo $file['image'][1]; ?> );return false;" title="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?> "> <img src="<?php print $manager->getThumbnail($file['relative']); ?> " alt="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?> "/> </a> <div class="edit"> <a href="<?php print $IMConfig['backend_url']; ?> __function=images&dir=<?php echo $relative; ?> &delf=<?php echo rawurlencode($file['relative']); ?> " title="Trash" onclick="return confirmDeleteFile('<?php echo $entry; ?> ');"><img src="<?php print $IMConfig['base_url']; ?> img/edit_trash.gif" height="15" width="15" alt="Trash" /></a> <a href="javascript:;" title="Edit" onclick="editImage('<?php echo rawurlencode($file['relative']); ?> ');"><img src="<?php print $IMConfig['base_url']; ?> img/edit_pencil.gif" height="15" width="15" alt="Edit" /></a> <?php if ($file['image']) { echo $file['image'][0] . 'x' . $file['image'][1]; } else { echo $entry; } ?> </div> </div> <?php } } }
/** * Draw folders and files. Changed by Afru */ function drawDirs_Files($list, &$manager) { global $relative, $afruViewType, $IMConfig, $insertMode; switch ($afruViewType) { case 'listview': $maxNameLength = 30; ?> <table class="listview"> <thead> <tr><th colspan="2">Name</th><th>Size</th><th>Image Size</th><th>Date Modified</th><th> </th></tr></thead> <tbody> <?php // start of foreach for draw listview folders . foreach ($list[0] as $path => $dir) { ?> <tr> <td><img src="<?php print $IMConfig['base_url']; ?> icons/folder_small.gif" alt="" /></td> <th nowrap><a href="<?php print $IMConfig['backend_url']; ?> __function=images&mode=<?php echo $insertMode; ?> &dir=<?php echo rawurlencode($path); ?> &viewtype=<?php echo $afruViewType; ?> " onclick="updateDir('<?php echo $path; ?> ')" title="<?php echo $dir['entry']; ?> "> <?php if (strlen($dir['entry']) > $maxNameLength) { echo substr($dir['entry'], 0, $maxNameLength) . "..."; } else { echo $dir['entry']; } ?> </a></th> <td colspan="2" nowrap>Folder</td> <td nowrap><?php echo date("d.m.y H:i", $dir['stat']['mtime']); ?> </td> <td class="actions" nowrap> <a href="<?php print $IMConfig['backend_url']; ?> __function=images&mode=<?php echo $insertMode; ?> &dir=<?php echo $relative; ?> &deld=<?php echo rawurlencode($path); ?> &viewtype=<?php echo $afruViewType; ?> " title="Trash" onclick="return confirmDeleteDir('<?php echo $dir['entry']; ?> ', <?php echo $dir['count']; ?> );" style="border:0px;"><img src="<?php print $IMConfig['base_url']; ?> img/edit_trash.gif" height="15" width="15" alt="Trash" border="0" /></a> </td> </tr> <?php } // end of foreach for draw listview folders . clearstatcache(); // start of foreach for draw listview files . foreach ($list[1] as $entry => $file) { ?> <tr> <td><img src="<?php print $IMConfig['base_url']; if (is_file('icons/' . $file['ext'] . '_small.gif')) { echo "icons/" . $file['ext'] . "_small.gif"; } else { echo $IMConfig['default_listicon']; } ?> " alt="" /></td> <th><a href="#" class="thumb" style="cursor: pointer;" onclick="selectImage('<?php echo $file['relative']; ?> ', '<?php echo preg_replace('#\\..{3,4}$#', '', $entry); ?> ', <?php echo $file['image'][0]; ?> , <?php echo $file['image'][1]; ?> );return false;" title="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?> " <?php if ($insertMode == 'image') { ?> onmouseover="showPreview('<?php echo $file['relative']; ?> ')" onmouseout="showPreview(window.parent.document.getElementById('f_url').value)" <?php } ?> > <?php if (strlen($entry) > $maxNameLength) { echo substr($entry, 0, $maxNameLength) . "..."; } else { echo $entry; } ?> </a></th> <td><?php echo Files::formatSize($file['stat']['size']); ?> </td> <td><?php if ($file['image'][0] > 0) { echo $file['image'][0] . 'x' . $file['image'][1]; } ?> </td> <td nowrap><?php echo date("d.m.y H:i", $file['stat']['mtime']); ?> </td> <td class="actions"> <a href="<?php print $IMConfig['backend_url']; ?> __function=images&dir=<?php echo $relative; ?> &delf=<?php echo rawurlencode($file['relative']); ?> &mode=<?php echo $insertMode; ?> &viewtype=<?php echo $afruViewType; ?> " title="Trash" onclick="return confirmDeleteFile('<?php echo $entry; ?> ');"><img src="<?php print $IMConfig['base_url']; ?> img/edit_trash.gif" height="15" width="15" alt="Trash" border="0" /></a> <?php if ($IMConfig['allow_rename']) { ?> <a href="#" title="Rename" onclick="renameFile('<?php echo rawurlencode($file['relative']); ?> '); return false;"><img src="<?php print $IMConfig['base_url']; ?> img/edit_rename.gif" height="15" width="15" alt="Rename" border="0" /></a> <?php } ?> <?php if ($IMConfig['img_library'] && $IMConfig['allow_edit_image'] && $file['image'][0] > 0) { ?> <a href="javascript:;" title="Edit" onclick="editImage('<?php echo rawurlencode($file['relative']); ?> ');"><img src="<?php print $IMConfig['base_url']; ?> img/edit_pencil.gif" height="15" width="15" alt="Edit" border="0" /></a> <?php } ?> </td> </tr> <?php } //end of foreach of draw listview files ?> </tbody> </table> <?php break; case 'thumbview': // thumbview is default // thumbview is default default: $maxFileNameLength = 11; $maxFolderNameLength = 13; // start of foreach for draw thumbview folders. foreach ($list[0] as $path => $dir) { ?> <div class="dir_holder"> <a class="dir" href="<?php print $IMConfig['backend_url']; ?> __function=images&mode=<?php echo $insertMode; ?> &dir=<?php echo rawurlencode($path); ?> &viewtype=<?php echo $afruViewType; ?> " onclick="updateDir('<?php echo $path; ?> ')" title="<?php echo $dir['entry']; ?> "><img src="<?php print $IMConfig['base_url']; ?> img/folder.gif" height="80" width="80" alt="<?php echo $dir['entry']; ?> " /></a> <div class="edit"> <a href="<?php print $IMConfig['backend_url']; ?> __function=images&mode=<?php echo $insertMode; ?> &dir=<?php echo $relative; ?> &deld=<?php echo rawurlencode($path); ?> &viewtype=<?php echo $afruViewType; ?> " title="Trash" onclick="return confirmDeleteDir('<?php echo $dir['entry']; ?> ', <?php echo $dir['count']; ?> );"><img src="<?php print $IMConfig['base_url']; ?> img/edit_trash.gif" height="15" width="15" alt="Trash" /></a> <?php if (strlen($dir['entry']) > $maxFolderNameLength) { echo substr($dir['entry'], 0, $maxFolderNameLength) . "..."; } else { echo $dir['entry']; } ?> </div> </div> <?php } // end of foreach for draw thumbview folders. // start of foreach for draw thumbview files. foreach ($list[1] as $entry => $file) { $afruimgdimensions = $manager->checkImageSize($file['relative']); $thisFileNameLength = $maxFileNameLength; ?> <div class="thumb_holder" id="holder_<?php echo asc2hex($entry); ?> "> <a href="#" class="thumb" style="cursor: pointer;" onclick="selectImage('<?php echo $file['relative']; ?> ', '<?php echo preg_replace('#\\..{3,4}$#', '', $entry); ?> ', <?php echo $file['image'][0]; ?> , <?php echo $file['image'][1]; ?> );return false;" title="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?> "> <img src="<?php print $manager->getThumbnail($file['relative']); ?> " alt="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?> " /> </a> <div class="edit"> <a href="<?php print $IMConfig['backend_url']; ?> __function=images&mode=<?php echo $insertMode; ?> &dir=<?php echo $relative; ?> &delf=<?php echo rawurlencode($file['relative']); ?> &viewtype=<?php echo $afruViewType; ?> " title="Trash" onclick="return confirmDeleteFile('<?php echo $entry; ?> ');"><img src="<?php print $IMConfig['base_url']; ?> img/edit_trash.gif" height="15" width="15" alt="Trash" /></a> <?php if ($IMConfig['allow_rename']) { ?> <a href="#" title="Rename" onclick="renameFile('<?php echo rawurlencode($file['relative']); ?> '); return false;"><img src="<?php print $IMConfig['base_url']; ?> img/edit_rename.gif" height="15" width="15" alt="Rename" /></a> <?php $thisFileNameLength -= 3; } ?> <?php if ($IMConfig['img_library'] && $IMConfig['allow_edit_image'] && $file['image'][0] > 0) { ?> <a href="javascript:;" title="Edit" onclick="editImage('<?php echo rawurlencode($file['relative']); ?> ');"><img src="<?php print $IMConfig['base_url']; ?> img/edit_pencil.gif" height="15" width="15" alt="Edit" /></a> <?php $thisFileNameLength -= 3; } ?> <?php if (strlen($entry) > $thisFileNameLength + 3) { echo strtolower(substr($entry, 0, $thisFileNameLength)) . "..."; } else { echo $entry; } ?> </div> </div> <?php } //end of foreach of draw thumbview files } }
/** * Draw the files in an table. */ function drawFiles($list, &$manager, $i) { global $relative; $image_per_line = 5; foreach ($list as $entry => $file) { $i++; if ($i == 1) { echo "<tr>"; } ?> <td><table width="100" cellpadding="0" cellspacing="0"><tr><td class="block"> <a href="<?php echo "{$manager->config['base_url']}{$file['relative']}"; ?> " target="_blank" title="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?> "><img src="<?php if (function_exists('imagecreate')) { echo $manager->getThumbnail($file['relative']); } else { if ($file['image']) { $size_x = $file['image'][0]; $size_y = $file['image'][1]; } if ($size_x < 96 && $size_y < 96) { } elseif ($size_x > $size_y) { $size_y = round($size_y / ($size_x / 96)); $size_x = 96; } else { $size_x = round($size_x / ($size_y / 96)); $size_y = 96; } echo "{$manager->config['base_url']}{$file['relative']}"; echo "\" width=\"{$size_x}\" height=\"{$size_y}"; } ?> " alt="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?> "/></a> </td></tr><tr><td class="edit"> <a href="images.php?dir=<?php echo $relative; ?> &delf=<?php echo rawurlencode($file['relative']); ?> " title="Trash" onclick="return confirmDeleteFile('<?php echo $entry; ?> ');"><img src="img/edit_trash.gif" height="15" width="15" alt="Trash"/></a><a href="javascript:;" title="Edit" onclick="editImage('<?php echo rawurlencode($file['relative']); ?> ');"><img src="img/edit_pencil.gif" height="15" width="15" alt="Edit"/></a> <?php if ($file['image']) { echo $file['image'][0] . 'x' . $file['image'][1]; } else { echo $entry; } ?> </td></tr></table></td> <?php if ($i == $image_per_line) { echo "</tr>"; $i = 0; } } //foreach return $i; }
function getDiskInfo() { if (empty($this->config['max_foldersize_mb'])) { return ''; } $tmpFreeSize = $this->config['max_foldersize_mb'] * 1048576 - Files::dirSize($this->getImagesDir()); if (!is_numeric($tmpFreeSize) || $tmpFreeSize < 0) { $tmpFreeSize = 0; } return 'Total Size : $max_foldersize_mb=' . $this->config['max_foldersize_mb'] . '$ MB, Free Space: $free_space=' . Files::formatSize($tmpFreeSize) . '$'; }
/** * Draw the files in an table. */ function drawFiles($list, &$manager) { global $relative; global $IMConfig; // add filename with course code in it // here filename is images/gallery/COMES.jpg // it should be /chamilo1884url/courses/COURSTESTSIMSUURLAPP/document/ global $_configuration; //var topDoc = window.top.document; $course_id = api_get_course_id(); $in_course = $course_id != -1 ? true : false; foreach ($list as $entry => $file) { //$chamiloPath = '/'.$_configuration['url_append'].'/courses/'.api_get_course_path().'/document'.$file['relative']; ?> <td><table width="100" cellpadding="0" cellspacing="0"><tr><td class="block"> <!-- change <?php echo $file['relative']; ?> with <?php echo $chamiloPath; ?> <a href="javascript: void(0);" onclick="selectImage('<?php echo $file['relative']; ?> ', '<?php echo $entry; ?> ', <?php echo $file['image'][0]; ?> , <?php echo $file['image'][1]; ?> );"title="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?> "><img src="<?php echo $manager->getThumbnail($file['relative']); ?> " alt="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?> "/></a> --> <a href="javascript: void(0);" onclick="selectImage('<?php echo $file['relative']; ?> ', '<?php echo $entry; ?> ', <?php echo $file['image'][0]; ?> , <?php echo $file['image'][1]; ?> );"title="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?> "><img src="<?php echo $manager->getThumbnail($file['relative']); ?> " alt="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?> "/></a> </td></tr><tr><td class="edit" style="padding-top: 5px;"> <?php if ($IMConfig['allow_delete']) { ?> <a href="images.php?dir=<?php echo $relative; ?> &delf=<?php echo rawurlencode($file['relative']); ?> " title="Trash" onclick="return confirmDeleteFile('<?php echo $entry; ?> ');"><img src="img/edit_trash.gif" height="15" width="15" alt="Trash"/></a> <?php } ?> <?php if ($IMConfig['allow_edit']) { ?> <a href="javascript: void(0);" title="Edit" onclick="editImage('<?php echo rawurlencode($file['relative']); ?> ');"><img src="img/edit_pencil.gif" height="15" width="15" alt="Edit"/></a> <?php } ?> <?php if ($file['image']) { echo $file['image'][0] . 'x' . $file['image'][1]; } else { echo $entry; } ?> </td></tr></table></td> <?php } //foreach }