|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-08-28 06:58 UTC] tony2001@php.net
[2006-08-28 09:51 UTC] bjori@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 12:00:01 2025 UTC |
Description: ------------ The manual said that "w" mode for fopen() will place the file pointer at the beginning of the file and truncate the file to zero length. But the file cannot be truncated using that "w" mode by fopen(). Reproduce code: --------------- <? $file = "t.log"; $add_content = "add this"; /* prepare the file to be truncated */ $fh = fopen($file, 'w'); $res = fwrite($fh, $add_content) or die("write file error"); fclose($fh); echo $file . " size : " . filesize($file) . "bytes. \n"; $sh = fopen($file, 'w'); fclose($sh); echo $file . " size : " . filesize($file) . "bytes. \n"; ?> Expected result: ---------------- t.log size : 8bytes. t.log size : 0bytes. Actual result: -------------- t.log size : 8bytes. t.log size : 8bytes.