Jump to content

fwrite not working...


zachtuggle

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/222947-fwrite-not-working/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/222947-fwrite-not-working/#findComment-1152751
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.