Results 1 to 2 of 2

Thread: Edit multiple txt files from 1 php page

  1. #1
    Join Date
    Jul 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Edit multiple txt files from 1 php page

    I am trying to edit multiple text files from a single php code/page. I want there to be a box for each text file I want to edit so they can all be updated on the same page at the same time. I have a code that works well for what I want to do. However this only has one form to edit one text file and Im not to familar with php to edit it and add another box and was wondering if someone else could help me fix it?

    The reason I am doing this is because I have a flash file that has certain areas that load external text files. I would like to be able to edit all these text files so that I can easily update my flash from one single page if you catch my drift.

    here is the code I am using and a link to the page its on so you can see it in action http://missodessa.net/php/editsomethingtxt.php

    ANy help would be greatly appreciated :-)



    PHP Code:
    <?php
    if (isset($_POST['submit'])) {

    $myFile "something.txt";
    $fh fopen($myFile'w') or die("can't open file");
    $stringData stripslashes($_POST['sf']);
    fwrite($fh$stringData);
    fclose($fh);

    header('Location: http://missodessa.net/php/editsomethingtxt.php?a=done');

    }
    ?>

    Inside body:
    <form action="" method="post">
    <textarea name="sf" cols="40" rows="6">
    <?php
    $myFile 
    "something.txt";
    $fh fopen($myFile'r');
    $theData fgets($fh);
    fclose($fh);
    echo 
    $theData;
    ?></textarea>
    <br />
    <input type="submit" name="submit" value="Edit" />
    </form>

    <?php
    if ($_GET['a'] == 'done') {
    echo 
    'The file was saved and now it says:<br /><br />';

    $myFile "something.txt";
    $fh fopen($myFile'r');
    $theData fgets($fh);
    fclose($fh);
    echo 
    $theData;

    }
    ?>

  2. #2
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    First make sure the text file is chmod-ed to 777, (do this you your ftp client)
    If that doesn't work, wherever your code is this:
    PHP Code:
    $myFile "something.txt"
    $fh fopen($myFile'r'); 
    $theData fgets($fh); 
    fclose($fh); 
    echo 
    $theData
    replace with
    PHP Code:
    $theData file_get_contents("something.txt");
    echo 
    $theData
    and then replace the submiting code with this:
    PHP Code:
    if (isset($_POST['submit'])) { 

    $stringData stripslashes($_POST['sf']); 
    file_put_contents("something.txt"$stringData);

    header('Location: http://missodessa.net/php/editsomethingtxt.php?a=done'); 


    *Untested
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •