Bug #18006 Updated: more info

From: Date: Thu, 27 Jun 2002 02:50:54 +0000
Subject: Bug #18006 Updated: more info
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-12192@lists.php.net to get a copy of this message
ID: 18006 Updated by: sniper@php.net Reported By: ilia@prohost.org -Status: Open +Status: Feedback -Bug Type: Scripting Engine problem +Bug Type: Filesystem function related Operating System: Linux PHP Version: 4.2.1 New Comment: What happens here is that you open a file in append mode and set the filepointer in the end of the file. Now when you truncate it to 100 bytes, the filepointer is still in the end. And when you add the 100 bytes, they're added in the end. You should open the file in 'w' mode. AFAIK, this is the correct behaviour. Previous Comments: ------------------------------------------------------------------------ [2002-06-26 21:08:26] ilia@prohost.org Sorry, the 2nd example is wrong, here is the correct one. <?php $fp = fopen('a', 'a+'); $s=ftell($fp); fseek($fp, $s+100, SEEK_SET); fseek($fp, $s, SEEK_SET); fwrite($fp, str_repeat('1', 100)); fclose($fp); ?> ------------------------------------------------------------------------ [2002-06-26 21:06:47] ilia@prohost.org When doing the following in php, the result is a file that is 200 bytes, 100 bytes of NULL and 100 bytes of the actual data. <?php $fp = fopen('a', 'a+'); $s=ftell($fp); ftruncate($fp, $s+100); fwrite($fp, str_repeat('1', 100)); fclose($fp); ?> In reality there should be a 100 byte file, full of 1s. However, this example works <?php $fp = fopen('a', 'a+'); $s=ftell($fp); ftruncate($fp, $s+100, SEEK_SET); fseek($fp, $s, SEEK_SET); fwrite($fp, str_repeat('1', 100)); fclose($fp); ?> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=18006&edit=1

« previous php.bugs (#12192) next »