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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.