473,408 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Writing to a text file

Is there a way of creating a seperate text file on a server every time a
form is sent?

--
¿ Trigger ?
http://www.magic2k.com/
http://www.oddmap.co.uk
Jul 19 '05 #1
10 4573
Neil Trigger wrote:
Is there a way of creating a seperate text file on a server every time a
form is sent?


Certainly, but why don't you use a database? A clogged up directory full
of thousands of text-files bites you in the end.

--
Nobody ever forgets where he buried the hatchet.
-- Kin Hubbard
Jul 19 '05 #2
Neil Trigger wrote:
Is there a way of creating a seperate text file on a server every
time a form is sent?


Where is the problem?

jue
Jul 19 '05 #3

"Neil Trigger" <em***@magic2k.com> wrote in message
news:KK*******************@news-binary.blueyonder.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_ADDR'}

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
Jul 19 '05 #4
Steven Mocking wrote:

Neil Trigger wrote:
Is there a way of creating a seperate text file on a server every time a
form is sent?


Certainly, but why don't you use a database? A clogged up directory full
of thousands of text-files bites you in the end.


I agree, but if you have an application that doesn't see very heavy use
and don't have a db on the server you are using like this one project I
have done. What you can do is have your script get the time then append
000 to the end, then try to open for reading a file of that name, if it
opens you know it already exist so then move on to 001 and see if that
exists, keep going till find a file that doesn't exist and then create
it. This isn't the best solution and will cause problems if it has
heavy use but for simple projects that are low usage it works fine.
Another option would be to append the IP address of the incoming request
and the port number the client is using although I'm not sure how to
find the port the client is sending on but there must be a way.

Chris W
Jul 19 '05 #5
Use time stamp as a filename.

"Neil Trigger" <em***@magic2k.com> wrote in message
news:KK*******************@news-binary.blueyonder.co.uk...
Is there a way of creating a seperate text file on a server every time a
form is sent?

--
¿ Trigger ?
http://www.magic2k.com/
http://www.oddmap.co.uk

Jul 19 '05 #6
Thank you all for your advise. I thought that the text file'd be the best
way, but upon reflection I think a database might be the best way. I have a
MySQL database system thing on my webserver that I've not played with to any
great (or very clever) extent.
Would I need to subscribe to alt.database.integration or something and ask
them? ;o)

--
¿ Trigger ?
http://www.magic2k.com/
http://www.oddmap.co.uk
Jul 19 '05 #7
very true. I'd forgotten about that one. thanks
Jul 19 '05 #8
[fullquote]
Nick Santos wrote:
very true.
What is true?
I'd forgotten about that one.
What did you forget about?
thanks


Thanks for what?

Without some sort of context your statement is incomprehensible.

jue
Jul 19 '05 #9
"Jürgen Exner" <ju******@hotmail.com> wrote in message
news:98****************@nwrddc01.gnilink.net...
[fullquote]
Nick Santos wrote:
very true.


What is true?
I'd forgotten about that one.


What did you forget about?
thanks


Thanks for what?

Without some sort of context your statement is incomprehensible.

jue


I'd forgotten about using a timestamp as a filename. one sure way to not get
overwrites as long as it's specified well enough. I don't usually delete the
content, but for some reason I did with that one. Sorry about that
Jul 19 '05 #10
Thanks everyone for your help.
You've posted a lot of useful info.

--
¿ Trigger ?
http://www.magic2k.com/
http://www.oddmap.co.uk
Jul 19 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: sp | last post by:
Hello everybody, I have an xml doc and I am trying to write the values from xml file to a tab delimited text file. Currently, what I am doing is I am reading xml file through XpathNavigaotr and...
2
by: melanieab | last post by:
Hi, I'm trying to store all of my data into one file (there're about 140 things to keep track of). I have no problem reading a specific string from the array file, but I wasn't sure how to...
3
by: CsharpNewcommer | last post by:
Hi Can someone tell me how to write the data from a TextBox (txt) or Label (lbl) to a text file to be printed. I have read the info from msdn.microsoft.com/library on "Writing Text to a File",...
2
by: Tony | last post by:
Yes, I need to specify a font type so that the characters will be evenly spaced when I write to a tab delimited text file. So how does one specify a font type to write/print and which font is...
0
by: Yunus's Group | last post by:
Yunus's Group May 23, 3:36 pm show options Newsgroups: microsoft.public.dotnet.languages.vb From: "Yunus's Group" <yunusasm...@gmail.com> - Find messages by this author Date: 23 May 2005...
3
by: nicolasg | last post by:
Hi, I'm trying to open a file (any file) in binary mode and save it inside a new text file. After that I want to read the source from the text file and save it back to the disk with its...
3
by: sethuganesh | last post by:
hi, i am not able to write a text properly in a text file in vb.net.below is the code that i have written. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As...
5
by: grinder | last post by:
first off, i am an extreme newbie to C. i am an undergrad research assistant and i have been shifted to a project that involves building a fairly involved c program. The part that i am stuck on now...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.