From 1b94bc530b5ac615702419af79e8fbc7e616a5ab Mon Sep 17 00:00:00 2001 From: pzinovkin Date: Fri, 7 Aug 2009 10:48:22 +0000 Subject: [PATCH] bytes to megabytes and kilobytes converting methods #nakon:ticket:327 git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@102 4cb57b5f-5bbd-dd11-951b-001d605cbbc5 --- classes/Cache.class.php | 4 ++-- classes/Format.class.php | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/classes/Cache.class.php b/classes/Cache.class.php index 6fe7b0e..ac46b8c 100644 --- a/classes/Cache.class.php +++ b/classes/Cache.class.php @@ -125,9 +125,9 @@ final class Cache */ function clearOld() { - $file = CACHE_PATH.'/'.$this->infofile; + $file = CACHE_PATH . '/' . $this->infofile; if (!file_exists($file) || date('Ymd', filemtime($file)) != date('Ymd')) { - exec('find '.CACHE_PATH.'/ -mtime +1 -delete'); //не удаляет папки сохраняя структуру + exec('find ' . CACHE_PATH . '/ -type f -mtime +1 -delete'); //не удаляет папки сохраняя структуру touch($file); } } diff --git a/classes/Format.class.php b/classes/Format.class.php index 989ca01..d69a175 100644 --- a/classes/Format.class.php +++ b/classes/Format.class.php @@ -191,6 +191,28 @@ class Format } return ''; } + + /** + * Байты в мегабайты + * @param int $bytes + * @return string + */ + public static function bytes2MB($bytes) + { + $mb = number_format((int) $bytes / 1024 / 1024, 2, '.', ''); + return preg_replace("/(\.?)0+$/", "", $mb) . 'МБ'; + } + + /** + * Байты в килобайты + * @param int $bytes + * @return string + */ + public static function bytes2KB($bytes) + { + $kb = number_format((int) $bytes / 1024, 2, '.', ''); + return preg_replace("/(\.?)0+$/", "", $kb) . 'КБ'; + } } /**