Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the size of files which more than 4GB----解决文件大于2G时的显示问题 #47

Closed
ivanhao opened this issue Dec 9, 2015 · 2 comments

Comments

@ivanhao
Copy link

ivanhao commented Dec 9, 2015

when I use the Kod in my Raspberry Pi II(OS is base in debian),I found that when the size of files whick more than 2GB,the files size are incorrect.then I fixed this problem with follow mathod:
/lib/function/file.function.php
turn :

function get_filesize($path){
    @$ret = abs(sprintf("%u",filesize($path))); 
    return (int)$ret;
}

to this:

function get_filesize($path){
    @$ret = abs(sprintf("%u",filesize($path))); 
    return $ret;
}

but, when files size over 4G,It's still incorrect.

then add a function "fsize()" before "get_filesize()":

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;
}

and turn get_filesize() to this:

function get_filesize($path){
    @$ret = fsize($path);
    return $ret;
}
@ragnaroks
Copy link

May work:
function get_filesize($path){
@$ret = abs(sprintf("%u",filesize($path)));
return (float)$ret;
}

@kalcaddle
Copy link
Owner

good job!

@ivanhao ivanhao closed this as completed Dec 10, 2015
@ivanhao ivanhao changed the title fix the size of files which more than 2GB----解决文件大于2G时的显示问题 fix the size of files which more than 4GB----解决文件大于2G时的显示问题,4G没解决 Dec 15, 2015
@ivanhao ivanhao reopened this Dec 15, 2015
@ivanhao ivanhao changed the title fix the size of files which more than 4GB----解决文件大于2G时的显示问题,4G没解决 fix the size of files which more than 4GB----解决文件大于2G时的显示问题 Feb 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants