php 文件大小超出,PHP文件大小超过4Gb

我正在运行Synology NAS服务器,

我正在尝试使用

PHP来获取文件的文件大小.

我正在尝试找到一个能够成功计算4Gb文件大小的函数.

文件大小($文件);仅适用于文件< 2Gb

sprintf(“%u”,filesize($file));仅适用于文件< 4Gb 我还尝试了我在php手册中找到的另一个函数,但它无法正常工作.

它随机适用于某些文件大小,但不适用于其他文件.

function fsize($file) {

// filesize will only return the lower 32 bits of

// the file's size! Make it unsigned.

$fmod = filesize($file);

if ($fmod < 0) $fmod += 2.0 * (PHP_INT_MAX + 1);

// find the upper 32 bits

$i = 0;

$myfile = fopen($file, "r");

// feof has undefined behaviour for big files.

// after we hit the eof with fseek,

// fread may not be able to detect the eof,

// but it also can't read bytes, so use it as an

// indicator.

while (strlen(fread($myfile, 1)) === 1) {

fseek($myfile, PHP_INT_MAX, SEEK_CUR);

$i++;

}

fclose($myfile);

// $i is a multiplier for PHP_INT_MAX byte blocks.

// return to the last multiple of 4, as filesize has modulo of 4 GB (lower 32 bits)

if ($i % 2 == 1) $i--;

// add the lower 32 bit to our PHP_INT_MAX multiplier

return ((float)($i) * (PHP_INT_MAX + 1)) + $fmod;

}

有任何想法吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值