Forum Moderators: coopster
At the moment, the forms logs the user issues to one long text file. I'd like it to log the issues to separate text files.
Any ideas how I can log each problem to separate text files and ensure that I don't overwrite any of the existing text files?
Here is the code so far, which logs to only 1 file so far. By the way, my Web space uses only PHP3.
ProcessForm.PHP:
-------------------
<?php
$myFileHandle = fopen('problem1.txt','a') or die("can't open file");
if (-1 == fwrite($myFileHandle,date("D j M Y g:i a").chr(10))) { die("can't write data"); }
if (-1 == fwrite($myFileHandle,$txtCompany.chr(10))) { die("can't write data"); }
if (-1 == fwrite($myFileHandle,$txtAddress.chr(10))) { die("can't write data"); }
if (-1 == fwrite($myFileHandle,$txtPhoneNumber.chr(10))) { die("can't write data"); }
if (-1 == fwrite($myFileHandle,$txtEmail.chr(10))) { die("can't write data"); }
if (-1 == fwrite($myFileHandle,$txtComments.chr(10))) { die("can't write data"); }
if (-1 == fwrite($myFileHandle,$txtProblem.chr(10))) { die("can't write data"); }
if (-1 == fwrite($myFileHandle,$txtProblemFound.chr(10))) { die("can't write data"); }
if (-1 == fwrite($myFileHandle,$txtReason.chr(10))) { die("can't write data"); }
if (-1 == fwrite($myFileHandle,$txtDateOfProblem.chr(10))) { die("can't write data"); }
if (-1 == fwrite($myFileHandle,$txtProblemCaused.chr(10))) { die("can't write data"); }
if (-1 == fwrite($myFileHandle,"-----".chr(10))) { die("can't write data"); }
fclose($myFileHandle) or die("can't close file");
?>
-------------------
Thanks for your suggestions,
May
I've used a slight variation - I've used the date and time this way:
$myFileHandle = fopen('problem-'.date("Ymd").'-'.date("His").'.txt','a') or die("can't open file");
This way, the files are named like this:
problem-20030927-164427.txt
which makes the date and time easy to read.
Now, if 2 people submit forms at the same moment in time could it cause a problem? The fact that we're opening the file with the 'a' attribute means it will append one problem to the other, right? This is ok, as we're not losing any data, but is there a way to force a new text file instead of appending?
Thx again, =o)
May