代码之家  ›  专栏  ›  技术社区  ›  Andrew Cooper

php文件大小报告旧大小

  •  19
  • Andrew Cooper  · 技术社区  · 16 年前

    以下代码是我编写的PHP Web服务的一部分。它接收一些上传的base64数据,对其进行解码,并将其附加到一个文件中。这一切都很好。

    问题是,当我在追加操作之后读取文件大小时,我得到的是追加操作之前的文件大小。

    $fileOut = fopen($filepath.$filename, "ab")
    fwrite($fileOut, base64_decode($data));
    fflush($fileOut);
    fclose($fileOut);
    
    $newSize = filesize($filepath.$filename);   // gives old file size
    

    我做错什么了?

    系统是:

    • PHP5.2.14
    • Apache 2.2.16
    • Linux内核2.6.18
    3 回复  |  直到 16 年前
        1
  •  36
  •   Pekka    16 年前
        2
  •  7
  •   Chris Laplante    16 年前

    http://us2.php.net/manual/en/function.filesize.php

    $fileOut = fopen($filepath.$filename, "ab")
    fwrite($fileOut, base64_decode($data));
    fflush($fileOut);
    fclose($fileOut);
    
    clearstatcache();
    
    $newSize = filesize($filepath.$filename);
    
        3
  •  2
  •   Juan    16 年前