/    Sign up×
Community /Pin to ProfileBookmark

continue writing to file

I’m using fwrite to write a log file after a query is executed, and it works, but it basically overwrites the data already in the file. So it only shows the last one.

[code=php]
//check to see if the file is there and is writeable
if(is_writable($filename)) {
if(!$handle = fopen($filename, “w+”)) {
echo “Can not open file ($filename)”;
exit;
}
//write content
if(fwrite($handle, $content) === FALSE) {
echo “Can not write to file ($filename)”;
exit;
}
fclose($handle);
}else{
echo “The file $filename is not writeable”;
}
[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@MstrBobDec 04.2004 — [code=php]
//check to see if the file is there and is writeable
if(is_writable($filename)) {
if(!$handle = fopen($filename, "a")) {
echo "Can not open file ($filename)";
exit;
}
//write content
if(fwrite($handle, $content) === FALSE) {
echo "Can not write to file ($filename)";
exit;
}
fclose($handle);
}else{
echo "The file $filename is not writeable";
}
[/code]


Change you fopen mode to 'a', which will append data to the end of the file. [URL=http://us2.php.net/fopen]fopen()[/URL]
Copy linkTweet thisAlerts:
@EJMAES1973authorDec 04.2004 — That fixed it. Thank you.
×

Success!

Help @EJMAES1973 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...