Hopefully the thread title makes sense, I'll explain what I want to be able to do: I currently use a .txt file stored in my Start Menu on various computers, that I have to manually sync with each other. The .txt file is basically a to-do list, along with links to various websites I find but want to spend more time looking at later on. I would like it if I could view the text file via the web instead, edit it as I see fit and 'save' it too. Is this at all possible? All within a standard browser interface, Javascript, PHP, MySQL etc. It just needs to be really simple and display a single text file. Any ideas?
Standard PHP file I/O will work, just read it into a buffer, display the buffer in a html text box on a form, when the submit button is pressed just write to the file.
[begs]Could you give me a few pointers - or a link to some code on the web? My php is non-existant![/begs] EDIT: I found this. Reading through it at the moment, but not entirely sure if it's what you mean.
OK, using the link in my post above, I have managed to get a form to save data to a .txt file. How do I call it when the form is first displayed, allowing it to be edited and re-saved? Code for index.html: Code: <form action="savedata.php" method="post"> Text: <textarea name="text" cols="256"></textarea> <input type="submit" value="Save Data >>"> </form> Code for savedata.php: Code: <?php $text = @$_POST["text"]; // Set the string to be written to the file $values = "To Do: $text\r\n"; // Open the file for truncated writing $fp = @fopen("file.txt", "w") or die("Couldn't open file.txt for writing!"); $numBytes = @fwrite($fp, $values) or die("Couldn't write values to file!"); @fclose($fp); echo "Wrote $numBytes bytes to file.txt successfully!"; ?>
Any ideas anyone? Just needing to call the .txt file when index.html is opened - within the form itself.
PHP: <? // Open the file for reading $fp = @fopen("file.txt", "r") or die("Couldn't open file.txt for Reading!"); $contents= @fread($fp, filesize("file.txt"));) or die("Couldn't read values from file!"); ?> <form action="savedata.php" method="post"> Text: <textarea name="text" cols="256"><? echo $contents; ?></textarea> <input type="submit" value="Save Data >>"> </form>
I can see what it should be doing, but it's displaying PHP: <? echo $contents ?> In the form, instead of the contents of the text file. Am I doing something retarded?
Sorry Doug, it's still displaying the echo message and not the data. Here's my index.html: PHP: <body> <? $fp = @fopen("tasks.txt", "r") or die("Couldn't open tasks.txt for Reading!"); $contents= @fread($fp, filesize("tasks.txt"));) or die("Couldn't read values from file!"); ?> <div align="center"> <form action="savedata.php" method="post"> <textarea name="text" cols="150" rows="30"><? echo $contents; ?></textarea> <br /> <br /> <input type="submit" value="Save Data >>" /> </form> </div> </body> And here's savedata.php: PHP: <? header("Location: http://myurlhere/"); $text = @$_POST["text"]; // Set the string to be written to the file $values = "$text\r\n"; // Open the file for truncated writing $fp = @fopen("tasks.txt", "w") or die("Couldn't open tasks.txt for writing!"); $numBytes = @fwrite($fp, $values) or die("Couldn't write values to file!"); ?> What am I doing wrong?
That's kinda cool, a glorified version of what I'm aiming for I guess. I'm annoyed by having emails and to do lists and bookmarks scattered across several PCs/Laptops, that I'm consolidating it all on a website.
First index.html should be index.php, and I was stupid, didn't fully type check. PHP: <html> <body> <? if(@$_POST["Save"]) { $text = @$_POST["text"]; // Set the string to be written to the file $values = "test2 $text \r\n"; // Open the file for truncated writing if(!$fp2) { $fp2 = fopen("tasks.txt", "w+") or die("Couldn't open tasks.txt for writing!"); } else { echo "File open"; } $numBytes = fwrite($fp2, $values) or die("Couldn't write values to file!"); fclose($fp2); $_POST = array(); } $fp = @fopen("tasks.txt", "r") or die("Couldn't open tasks.txt for Reading!"); $contents= @fread($fp, filesize("tasks.txt")) or die("Couldn't read values from file!"); fclose($fp); ?> <div align="center"> <form action="test.php" method="post"> <textarea name="text" cols="150" rows="30"><? echo $contents; ?></textarea> <br /> <br /> <input type="submit" value="Save Data >>" name="Save" /> </form> </div> </body> </html> That should work, I'm having some fwrite errors here, but I think thats a server problem.: EDIT: Changed the fopen for writing to w+
It works perfectly Doug! How can I repay you? I think I'll look into php more and teach it to myself, as I'm coming across many things that would work well using it.