note 41258 deleted from function.file-put-contents by irchtml

From: Date: Mon, 05 Apr 2004 02:55:30 +0000
Subject: note 41258 deleted from function.file-put-contents by irchtml
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-67640@lists.php.net to get a copy of this message
Note Submitter: mctrafik@mctrafik.net ---- There is a small function a wrote that's just as easy to use as file_put_contents(). It doesn't replace it, but some people might find it more useful, even though it's not as fast I guess. You can find it here: http://mctrafik.net/?i=15 But the thing looks kinda like this: function writetofile($file, $data, $keep = false) { if($keep) { if you don't use 'get()', then use lines below: $handle = @fopen($file, "r"); if($handle) { $precont = fread($handle, filesize($file)); fclose($handle); } } ignore_user_abort(true); $handle = @fopen($file, "w") or die("Permission denied to write to " . $file); @flock ($handle, LOCK_EX); fwrite($handle, trim($data)); if($keep) { fputs ($handle, "\n" . $precont); } @flock ($handle, LOCK_UN); fclose($handle); ignore_user_abort(false); unset($precont); }

« previous php.notes (#67640) next »