"Neil Trigger" <em***@magic2k. com> wrote in message
news:KK******** ***********@new s-binary.blueyond er.co.uk...
Is there a way of creating a seperate text file on a server every time a
form is sent?
I agree. I recently wrote a website that requires lots of coding and lots of
forms. Each form did a lot of text file reading and writing. I only have
about 30 users (who can use forms multiple times), but I have about 650
files and 450 folders for this. It's not the way to go. I've been slowly
switching it over to MySQL.
But to answer your question, yes. Therea are two ways you could do it
(assuming they aren't logged in. If they are logged in then you can do many
more). But If they aren't logged in, you can create a text file by ip
address, or text files can be created sequentially. You can also creat it
using any other data that you have on the user. If you create it by ip
address, you will want to append to the file if the user is allowed to
submit the form multiple times.
#_BEGIN_
# this is a demonstration of using the ip address to do it
# the ip address can be gotten using the following variable
$ENV{'REMOTE_AD DR'}
open (OUTF, ">>$ENV{'REMOTE _ADDR'}.txt"); #appending to prevent data loss
print OUTF "data";
close (OUTF);
#_END_
That is definitely the simpler one, assuming that the people aren't
submitting it multiple times.
#_BEGIN_
# This is a demonstration of making a text file by sequential numbering
opendir (DIR, "filedir");
@dir = readdir (DIR); #get all the files in the directory's names
closedir (DIR);
$end = @dir;
$i = 2; #we start i at two because of the . and .. entries in the directory
while($i<$end){
if(@dir[$i] =~ /\d.txt/){ #count the number of files in the directory
that are already made by this program
$n++; #n will eventually be the digit we use in the filename
}
$i++;
}
open (OUTF, ">>$n.txt") ; #still good to append just to prevent data loss
print OUTF "data";
close (OUTF);
#_END_
that one will create a seperate file and number them sequentially. If you
remove files from the directory though, be careful because it could start
writing in other ones and you won't know. If you want to be able to remove
files and have it still continure after the last one, then we'd check the
whole array using regular expressions for what the highest one is. I won't
put code for that here because I'm not sure if you'll be able to use it, and
I'm fairly bad at regular expressions. However, if you do decide you could
use it, I'd be happy to post some code.
-Nick