note 92418 added to function.filesize

From: Date: Thu, 23 Jul 2009 17:24:55 +0000
Subject: note 92418 added to function.filesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-158642@lists.php.net to get a copy of this message
This is an updated version of my previous filesize2bytes. The return type now it's really an int. /** * Converts human readable file size (e.g. 10 MB, 200.20 GB) into bytes. * * @param string $str * @return int the result is in bytes * @author Svetoslav Marinov * @author http://slavi.biz */ function filesize2bytes($str) { $bytes = 0; $bytes_array = array( 'B' => 1, 'KB' => 1024, 'MB' => 1024 * 1024, 'GB' => 1024 * 1024 * 1024, 'TB' => 1024 * 1024 * 1024 * 1024, 'PB' => 1024 * 1024 * 1024 * 1024 * 1024, ); $bytes = floatval($str); if (preg_match('#([KMGTP]?B)$#si', $str, $matches) && !empty($bytes_array[$matches[1]])) { $bytes *= $bytes_array[$matches[1]]; } $bytes = intval(round($bytes, 2)); return $bytes; } ---- Server IP: 66.207.199.35 Probable Submitter: 216.221.92.71 ---- Manual Page -- http://www.php.net/manual/en/function.filesize.php Edit -- https://master.php.net/note/edit/92418 Del: integrated -- https://master.php.net/note/delete/92418/integrated Del: useless -- https://master.php.net/note/delete/92418/useless Del: bad code -- https://master.php.net/note/delete/92418/bad+code Del: spam -- https://master.php.net/note/delete/92418/spam Del: non-english -- https://master.php.net/note/delete/92418/non-english Del: in docs -- https://master.php.net/note/delete/92418/in+docs Del: other reasons-- https://master.php.net/note/delete/92418 Reject -- https://master.php.net/note/reject/92418 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158642) next »