Home > Backend Development > PHP Tutorial > Development example of php code calculating file size

Development example of php code calculating file size

黄舟
Release: 2023-03-15 10:14:01
Original
1263 people have browsed it

In our previous articlephp download remote file and store it in local development example we introduced how to use php to download remote file and save it to local instance, then in our work, we often When encountering a file calculation, there is a function in PHP to obtain the number of bytes of the file size, but without units, which is not very convenient. Today I will introduce to you a detailed example of how to calculate the file size with units!

The first step is to download the PHP code library for calculating file size that we need to use in this course: http://www.php.cn/xiazai/leiku/689

Second step, after the download is completed, find the php class file we need, unzip it to our local directory, and create a new php file!

The third step, after completion, we need to call this class in the new php file and instantiate the class:

<?php
include_once "codejisuan.php"; //引入类文件
$dir_size=dirSize("D:/phpStudy/WWW"); //需要计算文件大小的名称
echo round($dir_size/pow(1024,1),2)."KB"; //输出
?>
Copy after login

Run this file and get the result as shown below:

Development example of php code calculating file size

The above is the detailed content of Development example of php code calculating 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