Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-21-2008, 10:09 AM   #1
Registered: Nov 2007
Posts: 69

Rep: Reputation: 15
simple php script to add line/file to text file

Hello, i have a txt file that i serve up on my apache server ( running on my debain box. I am very new to php and dont know a lot at all. I want users to go to a web site if they want to add a single line ("") or have an option to add a text file if they have multiple entries. If they upload a text file i want it to append (cat add.txt >> info.txt) to info.txt.

Please let me know your thoughts on this
Old 05-21-2008, 05:08 PM   #2
Registered: Nov 2007
Posts: 69

Original Poster
Rep: Reputation: 15
I figured it out here is what i did:

$fn = "file.txt";
$file = fopen($fn, "a+");
$size = filesize($fn);
$space.= "\n";
if($_POST['addition']) fwrite($file, $_POST['addition']);

$text = fread($file, $size);
fwrite ($file, $space);
<form action="<?=$PHP_SELF?>" method="post">
<input type="text" name="addition"/><br/>
<input type="submit"/>

file is the text file that you will add to


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script loop though text file:-1 line at a time. knockout_artist Linux - Newbie 2 05-04-2008 06:58 PM
How to add a text to first line of a text file? oskeewow Linux - Newbie 6 04-23-2008 12:40 PM
Shell script - how to show a specific line of a text file davi_cabral Linux - Software 3 09-28-2004 01:39 PM
Script to read a simple text file ravykanth Linux - Newbie 9 10-22-2003 04:15 AM
Display/Read line 'N' in a text file using script ganninu Linux - Newbie 2 10-13-2003 05:28 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:34 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration