文件大小()返回0?
我尝试使用 foreach.. 如果文件大小达到 1MB(1000000 字节),则将数组值插入到文件中。脚本创建一个新文件并将值放入其中...
这是我使用的代码:
foreach($array as $code){
if(filesize($file_name) < '1000000'){
$update_file = file_get_contents($file_name);
file_put_contents($file_name,$update_file.$code);
}else{
$open = fopen($file_name.rand('99999'),'w');
file_put_contents($file_name,$code);
}
echo filesize($file_name);
}
现在的问题是函数“filesize()”总是返回 0,但是如果我删除上面的代码并放入 < code>echo filesize($file_name); 仅在页面中..它返回正确的值(文件大小),该脚本也只生成 1 个文件,即使它变得超过 1MB,因为文件大小为 0 作为文件大小()函数返回!.
我检查了这个问题PHP问题:filesize()返回0文件包含很少的数据? 但即使我遵循答案#1,它仍然不起作用
我希望你理解我的问题..并且我对我的英语感到抱歉。
im trying to insert an array values into the file using foreach.. and if the file size became up to 1MB (1000000byte). the script create a new file and put the value inside...
this is the code what i used :
foreach($array as $code){
if(filesize($file_name) < '1000000'){
$update_file = file_get_contents($file_name);
file_put_contents($file_name,$update_file.$code);
}else{
$open = fopen($file_name.rand('99999'),'w');
file_put_contents($file_name,$code);
}
echo filesize($file_name);
}
now the problem is the function "filesize()" is always returning 0,, but if i remove the code above it and put echo filesize($file_name);
only in the page .. it return the right value (size of file), the script also make only 1 file even it became more than 1MB because the filesize is 0 as filesize() function return !.
i checked this question PHP Problem : filesize() return 0 with file containing few data?
but it still not working even i follow the answer #1
i wish that you understand my problem.. and im sorry for my english.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
函数文件大小在内部缓存
除此之外,每次写入后都需要显式使用
clearstatcache
,file_put_contents的用法似乎不正确,
请参阅手册了解更多信息
function filesize is cached internally
you need to explicitly use
clearstatcache
after each writebeside this, the usage of file_put_contents does not seem to be correct
please refer to the manual for more information