note 42328 deleted from function.ftruncate by bjori

From: Date: Thu, 06 Jul 2006 11:11:51 +0000
Subject: note 42328 deleted from function.ftruncate by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-114494@lists.php.net to get a copy of this message
Note Submitter: rc at opelgt dot org Reason: 5 ---- I was confused by the different fopen modes (r, r+, w, w+, a, a+). I wrote <?php $alt = '1234567890'; $neu = '13579'; $datei = 'test.txt'; $dh = fopen ($datei,"w"); fwrite($dh, $alt); fclose($dh); $dh = fopen ($datei,"a+"); // just alter the mode to test others rewind($dh); echo "Inhalt<BR>\nalt: ".fread($dh, filesize($datei))."<BR>\n"; ftruncate($dh, '0'); fwrite($dh, $neu); rewind($dh); echo 'neu: '.fread($dh, filesize($datei)); fclose($dh); ?> to find out what happens: 1. For me ftruncate to a size of 0 takes the pointer to position 0 successfully. Tested under UNIX with PHP 4.2.3 and under MacOSX 10.3 with PHP 4.3.4 2. Writing to a file opened with 'a' or 'a+' always begins writing at the end of the file. A rewind before doesnt help! ('a' for always append!) macrudi

« previous php.notes (#114494) next »