This section contains the detail about File Truncate In PHP.
In PHP, file truncation is the process of deleting data of a file. For this, we don't need any special function or method. This will be done automatically by opening file in the write mode.
Why we need file truncate
Sometimes, we need to store data for short span of time and it need to update after some interval. In that case, truncation is helpful to truncate these temporary files.
<?php // PHP code to truncate a file $myFileName = 'C:\testFile.txt'; $myFileHandle = fopen($myFileName, 'w') or die("cant open file"); fclose($myFileHandle); ?>
This will truncate/wipe out the previously existing data in the text file 'testFile.txt'.