note 32845 deleted from function.file-put-contents by didou

From: Date: Mon, 02 Feb 2004 14:34:08 +0000
Subject: note 32845 deleted from function.file-put-contents by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-64554@lists.php.net to get a copy of this message
Note Submitter: kevin@oceania.net ---- As there is no FILE_PREPEND for this function, here is an example of how you can write to the top of a file using file_put_contents(). Note: you must have permission to read and write to the file. <?php // just so we know it is broken error_reporting(E_ALL); // our file name $filename = 'myfile.txt'; // string to prepend to the file $text = 'This line goes at the top of the file'."\n"; // write the file contents into a buffer $buff = file_get_contents($filename); // write the new line and the buffer to the file if(!@file_put_contents($filename, $text.$buff)){ echo "Unable to write to file $filename"; }else{ // Give praise and thanks to the php gods echo "Success writing to $filename"; } ?>

« previous php.notes (#64554) next »