Dynamo wrote:
Hi all
I want to save the contents of a textarea within my webform as a text file
.txt on my webserver. In addition, I want to save it with the same file
name as the next autoincrement number in my sql table.(e.g. If I have 15
records in my table then the next autoincrement number will be 16 when I
add a new record and I want the text file to be saved as 16.txt)
sadly this is far as I have got cos im not sure how to do either of the
above.
<?php
$textfilecontents=$_POST['text'];
?>
Any help greatly appreciated
Regards
Dynamo
Hi Dynamo,
Wouldn't it be easier for you to store that text in the database itself?
That aside.
This is how to do that:
1) Get the next autoincrement.
(I have no clue about the excact syntax because you din't mention the
database.)
For now I take that you find that number and store it in $ai, ok?
2) Create a new file with the right name ($ai.txt).
to do this:
- go to
www.php.net
- look for the function fopen. (And when you are there, you can find all I
write here too, better, with more examples)
resource fopen ( string filename, string mode [, bool use_include_path [,
resource zcontext]])
So:
$filename = $ai.".txt";
$dir = "/home/dynamo/myfiles/"; // adjust to where you want to save
$fullpath = $dir.$filename;
$handle = fopen ($fullpath, "w+");
// now write
fwrite($handle, $_POST["text"]);
// and be a nice and close:
fclose($handle);
It is all on
www.php.net
This is a good startingpoint:
http://nl3.php.net/manual/en/ref.filesystem.php
Please note that I didn't implement any errorhandling.
But you should.
Regards,
Erwin Moller
PS: I didn't test the code.