473,837 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4631
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******** ***********@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
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******** ***********@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?

--
¿ 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.in tegration 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 incomprehensibl e.

jue
Jul 19 '05 #9
"Jürgen Exner" <ju******@hotma il.com> wrote in message
news:98******** ********@nwrddc 01.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 incomprehensibl e.

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

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

Similar topics

2
3782
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 manipulating all the nodes,elements and attributes than I am writing those values to a text file using stream writer. Now coming to my problem When I am writing data to the text file value of the last record is getting truncated. My code sample...
2
6864
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 replace just one item. I know I can get the entire array, then save the whole thing (with a for loop and if statements so that the changed data will be saved), but it seems like a lot of unnecessary reading and writing. Is there a way to directly save...
3
10345
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", and it only offers a solution for writing a text string and the system date. Help!!!!! I'm at a lost! Thanks
2
4496
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 best for evenness?
0
1723
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 12:36:14 -0700 Local: Mon,May 23 2005 3:36 pm Subject: Writing to text file Reply | Reply to Author | Forward | Print | Individual Message | Show original | Remove | Report Abuse
3
18967
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 original form. The problem is tha the binary source that I extract from the text file seems to be diferent from the source I saved. Here is my code: 1) handle=file('image.gif','rb')
3
3127
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 System.EventArgs) Handles Button2.Click Dim counter As Integer FileOpen(1, "c:\sample.txt", OpenMode.Random, , , 50) For Counter = 1 To 5
5
6218
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 is as follows: - i am trying to write code that will take any number of text inputs (names of other text files) and put them into a file line-by-line at the users request. meaning, i want the user to be able to type the strings and enter them...
6
5280
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;
0
9846
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9686
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10634
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9416
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7819
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7007
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5675
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4479
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4053
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.