Max Payne Posted December 4, 2007 Share Posted December 4, 2007 (edited) I don't understand something with php. I have this code: <?php if($_POST['content']){ $fff=fopen("notes.txt","w"); fwrite($fff, $_POST['content']); } ?> <form action='' method='POST'> <textarea name='content' cols='90' rows='10'> <?php if (file_exists("notes.txt")) readfile("notes.txt"); ?> </textarea> <br /> <input type='submit' value='Save Notes' class='inputbutton'> </form> and i have the notes.txt file created, but each time i use the note pad in the code above, it always has to have a space or a character in it. It can't be blank. Why is this? Edited December 4, 2007 by Max Payne Link to comment Share on other sites More sharing options...
Max Payne Posted December 5, 2007 Author Share Posted December 5, 2007 (edited) i'm sorry for bumping, but i need help with this. Edited December 5, 2007 by Max Payne Link to comment Share on other sites More sharing options...
Gerard Posted December 5, 2007 Share Posted December 5, 2007 Bumping is bad. I see you're writing to notes.txt if youre POSTing content, and then reading it if it exists. How do you know it "doesnt work" with an empty file? Do you get an error, or are you putting something else into the IF to test it? Why don't you always have the file there, and just see if it's empty or not? Link to comment Share on other sites More sharing options...
Max Payne Posted December 5, 2007 Author Share Posted December 5, 2007 when you try to remove all characters/and spaces, then click Save, the text is still there. It has to have atleast one character/space in it. How can i stop that. Link to comment Share on other sites More sharing options...
Gerard Posted December 5, 2007 Share Posted December 5, 2007 Ah okay - I think that's that's because fopen caches what goes through it. Use the b flag when opening it (as well as w), and use clearstatcache(). Or you could just say "if the file exists, fopen it" ? Link to comment Share on other sites More sharing options...
Max Payne Posted December 6, 2007 Author Share Posted December 6, 2007 okay, thanx Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now