zachtuggle Posted December 29, 2010 Share Posted December 29, 2010 I'm putting up a simple text editor for an "about me" website. Here's the basics from the edit page: <form action="done.php"> <textarea name="new" style="width: 600px; height: 500px;"> <? readfile("about.txt"); ?> </textarea> <input type="submit" value="Save" /> </form> The old text is put into the form, and once it is re-written, it is sent here: <? $_POST["save"] = fopen("about.txt", "w"); fwrite($_POST["save"], stripslashes($_REQUEST["new"])); fclose($_POST["save"]); ?> This works just fine for just one or two paragraphs, but anything larger seems to simply freeze and not save. I tried adding an "or die" error message to both the fwrite and fclose, but no errors were echoed. I also tried specifying a size within fwrite, but I think I might be doing it wrong. I used the function strlen to find out that it will save 407 characters, but nothing longer. Thank you for any help or suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/222947-fwrite-not-working/ Share on other sites More sharing options...
kenrbnsn Posted December 29, 2010 Share Posted December 29, 2010 Change the method on your form to "post", by default it's "get" and there is a limit to the amount of data you can pass through the URL <form action="done.php" method="post"> <textarea name="new" style="width: 600px; height: 500px;"> <?php readfile("about.txt"); ?> </textarea> <input type="submit" value="Save" /> </form> I would use the file_put_contents function instead <?php file_put_contents('about.txt', stripslashes($_POST['new'])); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/222947-fwrite-not-working/#findComment-1152751 Share on other sites More sharing options...
zachtuggle Posted December 29, 2010 Author Share Posted December 29, 2010 That works perfectly, thank you Ken! Quote Link to comment https://forums.phpfreaks.com/topic/222947-fwrite-not-working/#findComment-1152756 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.