LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   simple php script to add line/file to text file (https://www.linuxquestions.org/questions/programming-9/simple-php-script-to-add-line-file-to-text-file-643798/)

dnoy 05-21-2008 10:09 AM

simple php script to add line/file to text file
 
Hello, i have a txt file that i serve up on my apache server (http://192.168.0.1/info.txt) 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 ("www.google") 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

dnoy 05-21-2008 05:08 PM

I figured it out here is what i did:

<?php
$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);
fclose($file);
?>
<form action="<?=$PHP_SELF?>" method="post">
<input type="text" name="addition"/><br/>
<input type="submit"/>
</form>


file is the text file that you will add to


All times are GMT -5. The time now is 02:38 PM.