/**
* @desc: Created by PhpStorm.
* @author: icehill
* @date: 2018/1/18 14:56
*
*/
$fileName='autojump.png';
$filePath='./';
$file=$filePath.$fileName;
if (!file_exists($file)) {
echo 'file or directory exists.';
exit;
}
$size= filesize($fileName);
echo $size."\n";//文件字节数
echo getsize($size,'kb')."kb";//转成常用单位
/**
* @desc: 单位转换
* @author: icehill
* @param $size
* @param string $format
* @return string
*/
function getsize($size,$format='kb'){
$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);
}
作者心情:昨夜西风凋碧树,独上高楼,望尽天涯路。
如无特殊说明,文章均为本站原创,转载请注明出处
- 转载请注明来源:PHP获取文件大小
- 本文永久链接地址:http://icehill.cn/post/single/info/141.html