gpt4 book ai didi

php - 使用 php 清空文件

转载 作者:行者123 更新时间:2023-12-03 01:54:41 26 4
gpt4 key购买 nike

Possible Duplicate:
PHP: Is there a command that can delete the contents of a file without opening it?

如何使用 php 命令清空服务器上的 .txt 文件?

最佳答案

这是一种仅在文件已存在时才清空的方法,并且不存在使用 file_exists 的问题,因为文件可能在 file_exists 之间不再存在调用和 fopen 调用。

$f = @fopen("filename.txt", "r+");
if ($f !== false) {
ftruncate($f, 0);
fclose($f);
}

关于php - 使用 php 清空文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4944388/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com