note 41258 added to function.file-put-contents
| From: | mctrafik at mctrafik dot net | Date: | Sun, 04 Apr 2004 18:43:07 +0000 |
| Subject: | note 41258 added to function.file-put-contents | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-67626@lists.php.net to get a copy of this message | ||
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);
}
----
Manual Page -- http://www.php.net/manual/en/function.file-put-contents.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41258
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41258&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41258&report=yes
Search -- http://master.php.net/manage/user-notes.php