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

前端 未结 6 1812
面向向阳花
面向向阳花 2020-12-07 03:20

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

6条回答
  •  醉酒成梦
    2020-12-07 03:45

    ftruncate — Truncates a file to a given length

    Example

    $handle = fopen('/path/to/file', 'r+');
    ftruncate($handle, 0);
    fclose($handle);
    

    But you have to open the file.

提交回复
热议问题