note 41259 deleted from function.file-put-contents by irchtml
| From: | irchtml@php.net | Date: | Mon, 05 Apr 2004 02:55:41 +0000 |
| Subject: | note 41259 deleted from function.file-put-contents by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-67641@lists.php.net to get a copy of this message | ||
Note Submitter: mctrafik@mctrafik.net
----
There is a function that doesn't replace file_put_contents, but some might find it just as easy
to use, and it's a bit better, thought might be slower
Description etc is here:
http://mctrafik.net/?i=15
but the function looks kinda like this:
<?
function writetofile($file, $data, $keep = false)
{
if($keep)
{
$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);
}
?>