PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/application/modules/admin/views/helpers/Filesize.php

https://github.com/stinger/mailer
PHP | 63 lines | 37 code | 11 blank | 15 comment | 4 complexity | c5b23a6c58042a6e0703d9629883d24a MD5 | raw file
  1. <?php
  2. class Zend_View_Helper_Filesize
  3. {
  4. public $view;
  5. protected static $_baseurl = null;
  6. protected static $_cache = null;
  7. /**
  8. * Constructor
  9. */
  10. public function __construct()
  11. {
  12. if (null === self::$_baseurl)
  13. {
  14. $url = Zend_Controller_Front::getInstance()->getRequest()->getBaseUrl();
  15. $root = '/' . trim($url, '/');
  16. if ('/' == $root)
  17. {
  18. $root = '';
  19. }
  20. self::$_baseurl = $root . '/';
  21. }
  22. }
  23. /**
  24. * Output the formatted filesize
  25. *
  26. * @param int $bytes
  27. * @return string
  28. */
  29. public function filesize($bytes)
  30. {
  31. $symbol = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
  32. $exp = 0;
  33. $converted_value = 0;
  34. if( $bytes > 0 )
  35. {
  36. $exp = floor( log($bytes)/log(1024) );
  37. $converted_value = ( $bytes/pow(1024,floor($exp)) );
  38. }
  39. return sprintf( '%.2f '.$symbol[$exp], $converted_value );
  40. }
  41. /**
  42. * Set the view object
  43. *
  44. * @param Zend_View_Interface $view
  45. * @return void
  46. */
  47. public function setView(Zend_View_Interface $view)
  48. {
  49. $this->view = $view;
  50. }
  51. }
  52. ?>