栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

PHP filesize() 函数

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

PHP filesize() 函数

filesize

作用:函数返回指定文件的大小

语法

filesize(filename)

参数

filename:必需。规定要检查的文件。

返回值

返回文件大小的字节数,如果出错返回 FALSE 并生成一条 E_WARNING 级的错误。

filesize 示例

示例一

示例二

示例三

 array(
  "UNIT" => "TB",
  "VALUE" => pow(1024, 4)
     ),
     1 => array(
  "UNIT" => "GB",
  "VALUE" => pow(1024, 3)
     ),
     2 => array(
  "UNIT" => "MB",
  "VALUE" => pow(1024, 2)
     ),
     3 => array(
  "UNIT" => "KB",
  "VALUE" => 1024
     ),
     4 => array(
  "UNIT" => "B",
  "VALUE" => 1
     ),
 );

    foreach($arBytes as $arItem)
    {
 if($bytes >= $arItem["VALUE"])
 {
     $result = $bytes / $arItem["VALUE"];
     $result = str_replace(".", "," , strval(round($result, 2)))." ".$arItem["UNIT"];
     break;
 }
    }
    return $result;
}

?>

示例四

= 0)
    {//Check if it really is a small file (< 2 GB)
 if (fseek($file, 0, SEEK_END) === 0)
 {//It really is a small file
     fclose($file);
     return $size;
 }
    }
   
    //Quickly jump the first 2 GB with fseek. After that fseek is not working on 32 bit php (it uses int internally)
    $size = PHP_INT_MAX - 1;
    if (fseek($file, PHP_INT_MAX - 1) !== 0)
    {
 fclose($file);
 return false;
    }
   
    $length = 1024 * 1024;
    while (!feof($file))
    {//Read the file until end
 $read = fread($file, $length);
 $size = bcadd($size, $length);
    }
    $size = bcsub($size, $length);
    $size = bcadd($size, strlen($read));
   
    fclose($file);
    return $size;
}

推荐教程:《PHP》

以上就是PHP filesize() 函数的详细内容,更多请关注考高分网其它相关文章!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/262791.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号