相关疑难解决方法(0)

检查filesize而不在c ++中打开文件?

我正在尝试获取大文件(12gb +)的文件大小,我不想打开文件这样做,因为我认为这会占用大量资源.有没有好的API可以这样做?我在Windows环境中.

c++ windows winapi

28
推荐指数
5
解决办法
3万
查看次数

人类可读的文件大小

function humanFileSize($size)
{
    if ($size >= 1073741824) {
      $fileSize = round($size / 1024 / 1024 / 1024,1) . 'GB';
    } elseif ($size >= 1048576) {
        $fileSize = round($size / 1024 / 1024,1) . 'MB';
    } elseif($size >= 1024) {
        $fileSize = round($size / 1024,1) . 'KB';
    } else {
        $fileSize = $size . ' bytes';
    }
    return $fileSize;
}
Run Code Online (Sandbox Code Playgroud)

...工作得很好,除了:我不能手动选择我需要显示的格式,比如我想以MB显示只有文件大小.目前,如果它在GB范围内,它只会以GB显示.

另外,如何将小数限制为2?

php filesize

27
推荐指数
6
解决办法
3万
查看次数

PHP x86如何在没有外部程序的情况下获取> 2 GB文件的文件大小?

我需要获得大小超过2 GB的文件的文件大小.(在4.6 GB文件上测试).没有外部程序有没有办法做到这一点?

当前状态:

  • filesize(),stat()fseek()失败
  • fread()feof()工作

通过读取文件内容可以获得文件大小(非常慢!).

$size = (float) 0;
$chunksize = 1024 * 1024;
while (!feof($fp)) {
    fread($fp, $chunksize);
    $size += (float) $chunksize;
}
return $size;
Run Code Online (Sandbox Code Playgroud)

我知道如何在64位平台上使用它(使用fseek($fp, 0, SEEK_END)ftell()),但我需要32位平台的解决方案.


解决方案:我已经为此启动了开源项目.

大文件工具

Big File Tools是在PHP中操作超过2 GB的文件所需的hacks集合(即使在32位系统上).

php file-io x86 filesize large-files

24
推荐指数
2
解决办法
2万
查看次数

PHP文件大小超过4Gb

我正在运行Synology NAS服务器,我正在尝试使用PHP来获取文件的文件大小.
我正在尝试找到一个能够成功计算4Gb文件大小的函数.

filesize($file);仅适用于文件<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 …
Run Code Online (Sandbox Code Playgroud)

php filesize

5
推荐指数
1
解决办法
2959
查看次数

标签 统计

filesize ×3

php ×3

c++ ×1

file-io ×1

large-files ×1

winapi ×1

windows ×1

x86 ×1