Print file size in Ko, Mo, Go, To, Po,...


SUBMITTED BY: Guest

DATE: March 27, 2015, 1:15 p.m.

FORMAT: PHP

SIZE: 418 Bytes

HITS: 1106

  1. function taille_fichier($octets) {
  2. $resultat = $octets;
  3. for ($i=0; $i < 8 && $resultat >= 1024; $i++) {
  4. $resultat = $resultat / 1024;
  5. }
  6. if ($i > 0) {
  7. return preg_replace('/,00$/', '', number_format($resultat, 2, ',', '')) . ' ' . substr('KMGTPEZY',$i-1,1) . 'o';
  8. } else {
  9. return $resultat . ' o';
  10. }
  11. }
  12. echo taille_fichier(1024); // affiche : 1 Ko
  13. ?>

comments powered by Disqus