In our previous article PHP download remote file storage to the local development example we introduced the use of PHP to download remote files and save to the local instance, then in our work, we often encounter a file calculation, PHP has to get the size of the file number of bytes of the function, but without units, This is not very convenient, today we will introduce how to achieve the calculation of file size with units of the example of the detailed!
The first step is to download the PHP code class library that we need to calculate the file size for this lesson: http://www.php.cn/xiazai/leiku/689
The second step, after the download, find the PHP class files we need, unzip to our local directory, create a new PHP file!
After the third step, we will call this class in the new PHP file, and instantiate the class:
<?phpinclude_once "codejisuan.php"; Introduce class file $dir_size=dirsize ("D:/phpstudy/www"); The name of the file size that needs to be computed echo round ($dir _size/pow (1024,1), 2). " KB "; Output?>
Run this file and get the results as shown: