php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #38621 failed to truncate file using fopen in "w" mode
Submitted: 2006-08-28 03:16 UTC Modified: 2006-08-28 09:51 UTC
From: rrlin923 at hotmail dot com Assigned: bjori (profile)
Status: Not a bug Package: Documentation problem
PHP Version: 5.1.5 OS: Linux
Private report: No CVE-ID: None
 [2006-08-28 03:16 UTC] rrlin923 at hotmail dot com
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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-28 06:58 UTC] tony2001@php.net
The documentation is apparently wrong.
 [2006-08-28 09:51 UTC] bjori@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

clearstatcache();
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 00:01:28 2024 UTC