IMP::sizeFormat PHP Method

sizeFormat() public static method

Get size display information.
public static sizeFormat ( integer $size ) : string
$size integer The byte size of data.
return string A formatted size string.
    public static function sizeFormat($size)
    {
        return $size >= 1048576 ? sprintf(_("%s MB"), self::numberFormat($size / 1048576, 1)) : sprintf(_("%s KB"), self::numberFormat($size / 1024, 0));
    }

Usage Example

Example #1
0
File: Zip.php Project: horde/horde
 /**
  * Return the rendered information about the Horde_Mime_Part object.
  *
  * URL parameters used by this function:
  *   - zip_contents: (integer) If set, show contents of ZIP file.
  *
  * @return array  See Horde_Mime_Viewer_Driver::render().
  */
 protected function _renderInfo()
 {
     global $injector;
     $vars = $injector->getInstance('Horde_Variables');
     if (!$this->getConfigParam('show_contents') && !$vars->zip_contents) {
         $status = new IMP_Mime_Status($this->_mimepart, _("This is a compressed file."));
         $status->addMimeAction('zipViewContents', _("Click to display the file contents."));
         $status->icon('mime/compressed.png');
         return array($this->_mimepart->getMimeId() => array('data' => '', 'status' => $status, 'type' => 'text/html; charset=UTF-8'));
     }
     $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/mime'));
     $view->addHelper('Text');
     $view->downloadclass = 'zipdownload';
     $view->files = array();
     $view->tableclass = 'zipcontents';
     $zlib = Horde_Util::extensionExists('zlib');
     foreach ($this->_getZipInfo() as $key => $val) {
         $file = new stdClass();
         $file->name = $val['name'];
         $file->size = IMP::sizeFormat($val['size']);
         /* TODO: Add ability to render in-browser for filetypes we can
          *       handle. */
         if (!empty($val['size']) && strstr($val['attr'], 'D') === false && ($zlib && $val['method'] == 0x8 || $val['method'] == 0x0)) {
             $file->download = $this->getConfigParam('imp_contents')->linkView($this->_mimepart, 'download_render', '', array('class' => 'iconImg downloadAtc', 'jstext' => _("Download"), 'params' => array('zip_attachment' => $key)));
         } else {
             $file->download = '';
         }
         $view->files[] = $file;
     }
     return array($this->_mimepart->getMimeId() => array('data' => $view->render('compressed'), 'type' => 'text/html; charset=UTF-8'));
 }
All Usage Examples Of IMP::sizeFormat