PHP:是否有命令可以删除文件内容而无需打开文件? [英] PHP: Is there a command that can delete the contents of a file without opening it?
问题描述
是否有任何方法可以删除php中文件的内容,我们是否有任何执行此操作的php命令,我知道unlink
,但我不想删除该文件,而只是想删除其中的内容该文件.
我有一个文件,该文件在调用getCurrentDBSnap
函数时传递给我,它从/home/test/incoming
文件夹中接收文件,并使用fputcsv
将currentDB表状态填充到该文件中,然后将文件放回/home/test/outgoing
中.
当前文件保留在传入文件夹中,当我可以调用函数getCurrentDBSnap
时,它将获取文件并以DB的最新状态覆盖它.
问:我的问题是,是否有可能代替覆盖文件,所以我们可以在getCurrentDBSnap
之后删除文件的内容,以使传入文件夹中的文件始终为空?>
希望这是有道理的:)
尝试 file_put_contents($filename, "")
;
或
unlink($filename);
touch($filename);
Is there any way to remove the contents of an file in php, do we have any php command that does that, I know unlink
but I do not want to delete the file instead I just want to remove the contents of that file.
I have an file which I pass while called a getCurrentDBSnap
function, it takes in the file from /home/test/incoming
folder and populates currentDB table state into the file using fputcsv
and puts back file to /home/test/outgoing
.
Currently file stays in incoming folder and when I can call the function getCurrentDBSnap
it would take the file and override with latest state of DB into it.
Q: My question is, is it possible instead of overwriting the file, we can remove the content of file after ever getCurrentDBSnap
such that file in incoming folder would be always empty ?
Hope it makes sense :)
Try file_put_contents($filename, "")
;
or
unlink($filename);
touch($filename);
这篇关于PHP:是否有命令可以删除文件内容而无需打开文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!