Jump to content


[ger - Germany] - Filesize


  • You cannot reply to this topic
No replies to this topic

#1 freemind

    Etomite Forum Newbie

  • Member
  • 22 posts

Posted 02 August 2005 - 08:43 PM

Snippet name: fileSize
Author: mark301
Version: 1.0 (Final)
Description: returns the file size in kb if the passed in filename
Translated into German: freemind

/* 
 * Benutze das Snippet wie folgt:
 * [[fileSize?filename=path/to/file.ext]] 
 * 
 * Bringt als Ergebnis auf der Seite:
 * Dateigröße: 42.28 KB
*/

if(!isset($filename)) {
   return $filename = 'Dateiname/Pfad nicht angegeben';
}

if (!function_exists('filesize_format')) {
/**
 * function filesize_format() - version 1.0
 * Formate a filesize to a human readable format
 *
 * @param  integer  bytes
 * @param  string  the decimal delimiter, default '.'
 * @param  string  the spacer between the filesize and the unit, default ' '
 * @param  boolean  if set to true, all units are written in lowercase, default false
 *
 * @return  string  the formated filesize
 *
 * @access  public
 *
 * Source: http://nl3.php.net/manual/nl/function.filesize.php#55019
 */
function filesize_format ($bytes, $decimal='.', $spacer=' ', $lowercase=false) {

  $bytes = max(0, (int)$bytes);
  $units = array('YB' => 1208925819614629174706176, // yottabyte
                 'ZB' => 1180591620717411303424,    // zettabyte
                 'EB' => 1152921504606846976,      // exabyte
                 'PB' => 1125899906842624,          // petabyte
                 'TB' => 1099511627776,            // terabyte
                 'GB' => 1073741824,                // gigabyte
                 'MB' => 1048576,                  // megabyte
                 'KB' => 1024,                      // kilobyte
                 'B'  => 0);                        // byte

  foreach ($units as $unit => $qty) {
     if ($bytes >= $qty)
   return number_format(!$qty ? $bytes: $bytes /= $qty, 2, $decimal, $spacer).$spacer.$unit;
   }
  } // end of 'filesize_format' function();
}

if (file_exists($filename)) {
 return $fileSize = 'Dateigröße: ' . filesize_format(filesize($filename));
} else {
 return $fileSize = 'Datei nicht gefunden: ' . $filename;
}

by
freemind





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users