note 41260 deleted from function.file-put-contents by nlopess
| From: | nlopess@php.net | Date: | Fri, 09 Apr 2004 19:33:36 +0000 |
| Subject: | note 41260 deleted from function.file-put-contents by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-67919@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);
}
?>