Home  >  Article  >  Backend Development  >  PHP method example code to obtain file size

PHP method example code to obtain file size

怪我咯
怪我咯Original
2017-07-14 11:23:392447browse

This article mainly introduces the method of php to obtain the file size. Friends who need it can refer to it

/**
 * Returns a human readable filesize
 */
function HumanReadableFilesize($size) {
    $mod = 1024; 
    $units = explode(' ','B KB MB GB TB PB');
    for ($i = 0; $size > $mod; $i++) {
        $size /= $mod;
    }
    return round($size, 2) . ' ' . $units[$i];
}

The above is the detailed content of PHP method example code to obtain file size. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn