PCTechTalkhttp://www.pctechtalk.com/forums/

Go Back   PCTechTalk > PC Tech > Web Related

Reply
 
LinkBack Thread Tools Display Modes
Old 02-16-2004, 06:40 PM   #1 (permalink)
Registered User
 
Colin-uk's Avatar
 
Join Date: Jan 2003
Location: UK
Posts: 928
Colin-uk is on a distinguished road
append to textfile with php

hi,

im wanting to append data to a txt file, i have this so far...

PHP Code:
<?php

$server_path 
"./"//Path to log directory 
$log_entries $_POST['name']. "" .$_POST['comments']. "" .$_POST['email']. "\n"
$fp fopen($server_path "stuff.txt""w+") or die("ERROR! Cannot create 'stuff.txt' file."); 

if (
$fp!= false



fwrite($fp$log_entries); 
fclose($fp); 



?>
but the data doesnt append, it just overwrites
ive looked at the manual and there doesnt seem to be a way of putting the file pointer at the end of the file

any help appreciated
thanks

Last edited by c0lin; 02-17-2004 at 05:13 AM.
Colin-uk is offline   Reply With Quote
Old 02-17-2004, 05:46 AM   #2 (permalink)
Da House Nerd
 
greffov's Avatar
 
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
greffov will become famous soon enough


'a' - Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.

the a of 'append'



taken from the online manual of fopen

RTFM!

__________________
Linux virusscanner detected a virus:
Windows 95 ... delete [Y/n] y
~
~

:wq
greffov is offline   Reply With Quote
Old 02-17-2004, 06:37 AM   #3 (permalink)
Registered User
 
Colin-uk's Avatar
 
Join Date: Jan 2003
Location: UK
Posts: 928
Colin-uk is on a distinguished road
oops,

ok maybe i need glasses or somthing...
lol

just one more question though (lol)...
is there anyway i could run the script from one server and have it write to a text file on another?
or is this impossible?

thanks again lol

Last edited by c0lin; 02-17-2004 at 08:29 AM.
Colin-uk is offline   Reply With Quote
Old 02-17-2004, 08:56 AM   #4 (permalink)
Da House Nerd
 
greffov's Avatar
 
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
greffov will become famous soon enough
yes, it's possible, in various ways:

1. when there is an NFS mount, simply write a file, like it's on the local hierarchy
2. write your own logging daemon, which writes a TCP socket down to a file
3. do it the PHP-way; create a page which writes something to a file, then call that page from the other server using fopen('http://my.server/logpage.php?message=log+this+message');

Of course you can write the logpage.php in such a way it only accepts call from the other server, and rejects all others....
__________________
Linux virusscanner detected a virus:
Windows 95 ... delete [Y/n] y
~
~

:wq
greffov is offline   Reply With Quote
Old 02-17-2004, 01:06 PM   #5 (permalink)
Registered User
 
Colin-uk's Avatar
 
Join Date: Jan 2003
Location: UK
Posts: 928
Colin-uk is on a distinguished road
thanks greffov, i,ll give it a try
Colin-uk is offline   Reply With Quote
Old 02-17-2004, 01:09 PM   #6 (permalink)
Da House Nerd
 
greffov's Avatar
 
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
greffov will become famous soon enough
no problem

I'll be waiting for the next Q
__________________
Linux virusscanner detected a virus:
Windows 95 ... delete [Y/n] y
~
~

:wq
greffov is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 07:37 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
2001 PCTechTalk