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

PHP method example code to obtain file size

怪我咯
Release: 2023-03-13 22:12:02
Original
2458 people have browsed it

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];
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template