Car Loan - Personal Loans - Mortgage Calculator - Debt Consolidation - Credit Cards

PDA

View Full Version : Write File in php


pulikuttann
Mar 6th 2007, 5:31 am
I am a newbie in php and I just entered the file writing.
I have created a file and write to it from the browser with input text box.
But when ever I write the older contents are rewritten.
Can I make it static ???

Help !!!

TwistMyArm
Mar 6th 2007, 6:12 am
When you say:
"But when ever I write the older contents are rewritten."

do you mean:
"But when ever I write the older contents are OVERwritten"?

If so, you need to open the file in APPEND mode. Instead of opening it with the 'w' or 'w+' flag, try using 'a' or 'a+'.

CodyRo
Mar 6th 2007, 6:32 am
http://us2.php.net/fopen
http://us2.php.net/fwrite

As mentioned above, use "append" or "a+"

Example:

<?php

$fp = fopen("file.txt", "a+");

fwrite($fp, "Hello! ");
fwrite($fp, "World!");

?>

pulikuttann
Mar 6th 2007, 6:35 am
When you say:
"But when ever I write the older contents are rewritten."

do you mean:
"But when ever I write the older contents are OVERwritten"?

If so, you need to open the file in APPEND mode. Instead of opening it with the 'w' or 'w+' flag, try using 'a' or 'a+'.


It was the problem and I fix it !!!
Thankz for it !!!

jitesh
Mar 14th 2007, 3:38 am
<?php $fp = fopen("file.txt", "w+"); fwrite($fp, "Hello! "); fwrite($fp, "World!");?>