php 获取文件大小源码:
<?php
$myfile = \"./test.txt\";
if (file_exists ($myfile)) {
$checksize=filesize ($myfile);
echo \"$checksize\";
} else {
echo \"The file doesn\'t exist!\";
}
?>
在PHP中,通过filesize函数可以取得文件的大小,文件大小是以字节数表示的。如果要转换文件大小的单位,可以自己定义函数来实现。
<?php
function getsize($size, $format) {
$p = 0;
if ($format == \'kb\') {
$p = 1;
} elseif ($format == \'mb\') {
$p = 2;
} elseif ($format == \'gb\') {
$p = 3;
}
$size /= pow(1024, $p);
return number_format($size, 3);
}
/* http://www.manongjc.com/article/1376.html */
$filename = \'./test.txt\';
$size = filesize($filename);
$size = getsize($size, \'kb\'); //进行单位转换
echo $size.\'kb\'; 继续阅读与本文标签相同的文章
-
Google Books迎15岁生日 重新调整后更加方便
2026-05-14栏目: 教程
-
Windows 7即将停止支援 今年被攻击次数大幅提升71%
2026-05-14栏目: 教程
-
你绝对用得到的Excel数据保护方法
2026-05-14栏目: 教程
-
火币:火币土耳其将成为世界增长最快的加密社区之一
2026-05-14栏目: 教程
-
马化腾果断出手!微信将封禁砍价链接,网友:朋友圈终于清静了
2026-05-14栏目: 教程
