PHP文件大小报告旧大小 [英] PHP filesize reporting old size

查看:96
本文介绍了PHP文件大小报告旧大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码是我编写的PHP Web服务的一部分.它需要一些上载的Base64数据,对其进行解码,然后将其附加到文件中.一切正常.

The following code is part of a PHP web-service I've written. It takes some uploaded Base64 data, decodes it, and appends it to a file. This all works fine.

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

The problem is that when I read the file size after the append operation I get the size the file was before the append operation.

$fileOut = fopen($filepath.$filename, "ab")
fwrite($fileOut, base64_decode($data));
fflush($fileOut);
fclose($fileOut);

$newSize = filesize($filepath.$filename);   // gives old file size

我在做什么错了?

系统为:

  • PHP 5.2.14
  • Apache 2.2.16
  • Linux内核2.6.18

推荐答案

在基于Linux的系统上,由filesize()提取的数据为"statcached".

On Linux based systems, data fetched by filesize() is "statcached".

尝试在文件大小调用之前调用 clearstatcache(); .

Try calling clearstatcache(); before the filesize call.

这篇关于PHP文件大小报告旧大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆