/bedita-app/vendors/_smartyPlugins/modifier.filesize.php
PHP | 52 lines | 24 code | 6 blank | 22 comment | 8 complexity | 1f437ac3ad4fae57d517f1384d90995e MD5 | raw file
Possible License(s): AGPL-1.0, AGPL-3.0, LGPL-3.0, LGPL-2.1, GPL-3.0
- <?php
- /*
- * Smarty plugin
- * -------------------------------------------------------------
- * Type: modifier
- * Name: filesize
- * Purpose: return size in Kilobyte, Megabyte, Gigabyte or Terabyte
- * -------------------------------------------------------------
- */
- /////////////////////////////////////////////
- function smarty_modifier_filesize($size) {
- /*
- // First check if the file exists.
- //if(!is_file("./".$file)) exit("File does not exist!");
- if(!is_file("./".$file)) {
- return $size."*fnp*";
- }
- */
- // Setup some common file size measurements.
- $kb = 1024; // Kilobyte
- $mb = 1024 * $kb; // Megabyte
- $gb = 1024 * $mb; // Gigabyte
- $tb = 1024 * $gb; // Terabyte
- //// Get the file size in bytes.
- //$size = filesize($file);
- //// If it's less than a kb we just return the size, otherwise we keep going until the size is in the appropriate measurement range. */
-
- if($size < $kb) {
- //return $size."b";
- $myfilesize = round($size/$kb,2)."KB";
- }
- else if($size < $mb) {
- $myfilesize = round($size/$kb,0)."KB";
- }
- else if($size < $gb) {
- $myfilesize = round($size/$mb,1)."MB";
- }
- else if($size < $tb) {
- $myfilesize = round($size/$gb,2)."GB";
- }
- else {
- $myfilesize = round($size/$tb,2)."TB";
- }
-
- return $myfilesize;
- }
- /////////////////////////////////////////////
- ?>