For Programmers: Free Programming Magazines  


Home > Archive > PHP Documentation > August 2006 > #38621 [Opn]: failed to truncate file using fopen in "w" mode









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author #38621 [Opn]: failed to truncate file using fopen in "w" mode
tony2001@php.net

2006-08-28, 3:57 am

ID: 38621
Updated by: tony2001@php.net
Reported By: rrlin923 at hotmail dot com
Status: Open
-Bug Type: *General Issues
+Bug Type: Documentation problem
Operating System: Linux
PHP Version: 5.1.5
New Comment:

The documentation is apparently wrong.


Previous Comments:
------------------------------------------------------------------------

[2006-08-28 03:16:30] 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.



------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=38621&edit=1
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com