Results 1 to 12 of 12

Thread: php - opening file to html form?

  1. #1
    Senior Member
    Join Date
    Apr 2005
    Location
    Bournemouth, Dorset
    Posts
    1,631
    Thanks
    13
    Thanked
    2 times in 2 posts

    php - opening file to html form?

    i know how to read, write and open files using php, but i cant quite work out how to open a file to a html <textarea> for editing and then saving.
    can any one help me with this?


    Edit: i basically want to modify a file and save. Just incase that wasnt clear
    Last edited by Ramedge; 08-10-2005 at 05:19 PM.

  2. #2
    Bigger than Jesus Norky's Avatar
    Join Date
    Feb 2005
    Posts
    1,579
    Thanks
    1
    Thanked
    8 times in 8 posts
    It would go something like:

    $file = 'C:\etc.txt';
    $fp = fopen($file, r);
    $file = fread($fp, filesize($file));
    echo "<textarea>$file</textarea>";

    Then you'd need a form handler to simply write the file back when its submitted.

  3. #3
    Senior Member
    Join Date
    Apr 2005
    Location
    Bournemouth, Dorset
    Posts
    1,631
    Thanks
    13
    Thanked
    2 times in 2 posts
    thank you very much for the quick reply Norky, much appreciated !
    that script is opening the file into the text area but dont i want to use 'b' to modify it?
    Edit: dont worry i think ive worked out that the 'b' function would be in the handler. Now having difficaulties working out how to do the handler.
    Last edited by Ramedge; 08-10-2005 at 05:47 PM.

  4. #4
    Bigger than Jesus Norky's Avatar
    Join Date
    Feb 2005
    Posts
    1,579
    Thanks
    1
    Thanked
    8 times in 8 posts
    You'd need to use: <textarea name="textarea>etc.</textarea>

    Use this page and just use one of their scripts for writing the file. The new contents of the file would be $_POST['textarea'] if you used my above example

  5. #5
    Senior Member
    Join Date
    Apr 2005
    Location
    Bournemouth, Dorset
    Posts
    1,631
    Thanks
    13
    Thanked
    2 times in 2 posts
    cheers
    Last edited by Ramedge; 08-10-2005 at 10:14 PM.

  6. #6
    Senior Member
    Join Date
    Apr 2005
    Location
    Bournemouth, Dorset
    Posts
    1,631
    Thanks
    13
    Thanked
    2 times in 2 posts
    Does any body have any ideas why this doesnt work?
    this is the code in openfile.php
    PHP Code:
    <form action="save.php" method="post">
    <? 
    $file 
    'home.txt';
    $fp fopen($filer);
    $file fread($fpfilesize($file));
    echo 
    "<textarea name = editcont cols= 60 rows= 15>$file</textarea>";
    ?>
    <br>
    <INPUT TYPE="submit" VALUE="Save">
    </form>
    and the code in save.php is
    PHP Code:
    <?  
    $msg 
    $_POST['editcont'];
    echo 
    $msg;
    $file 'home.txt';
    $fp fopen($filer) or die ("could not open");
    fwrite($fp$msg) or die ("could not save");

    ?>

    i put and if statement in to see if the file "home.txt" could be written to but it said it wasnt! it even said this for my news.txt file which i know you can write to!
    so i really dont know why this doesnt work, any ideas?

  7. #7
    Member
    Join Date
    Oct 2005
    Posts
    92
    Thanks
    0
    Thanked
    0 times in 0 posts
    You're going to kick yourself over whats wrong... You have opened the file with the flag r
    PHP Code:
    $fp fopen($filer); 
    Try 'w' or 'w+' and you should find your code works.

    PHP Code:
    $fp fopen($filew); 
    Nick

  8. #8
    Senior Member Kezzer's Avatar
    Join Date
    Sep 2003
    Posts
    4,863
    Thanks
    12
    Thanked
    5 times in 5 posts
    lmao, well done nick For the opening of the file you need to read it, for the writing you need to write. Even I didn't spot that

  9. #9
    Member
    Join Date
    Oct 2005
    Posts
    92
    Thanks
    0
    Thanked
    0 times in 0 posts
    Quote Originally Posted by Kezzer
    lmao, well done nick For the opening of the file you need to read it, for the writing you need to write. Even I didn't spot that
    I do this for a living so its something I do regularly. Now then anyone else need help?

    Nick

  10. #10
    Senior Member Kezzer's Avatar
    Join Date
    Sep 2003
    Posts
    4,863
    Thanks
    12
    Thanked
    5 times in 5 posts
    lol, I pretty much code for a living but PHP really isn't my area

    EDIT: But yes, check out my thread where i'm writing a very basic CMS

  11. #11
    Senior Member
    Join Date
    Apr 2005
    Location
    Bournemouth, Dorset
    Posts
    1,631
    Thanks
    13
    Thanked
    2 times in 2 posts
    ahh cheers nick !!

  12. #12
    Senior Member
    Join Date
    Apr 2005
    Location
    Bournemouth, Dorset
    Posts
    1,631
    Thanks
    13
    Thanked
    2 times in 2 posts
    Quote Originally Posted by Kezzer
    lEDIT: But yes, check out my thread where i'm writing a very basic CMS
    will do
    iam currently making a very simple CMS for Alevel computing

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Nero vision express saying:'Burn process failed'
    By johnnr892 in forum Help! Quick Relief From Tech Headaches
    Replies: 15
    Last Post: 11-12-2005, 11:43 PM
  2. The HTML bit of PHP - simple!
    By Vini in forum Software
    Replies: 14
    Last Post: 26-09-2005, 09:26 AM
  3. php email form
    By XA04 in forum Software
    Replies: 4
    Last Post: 11-05-2005, 10:17 AM
  4. Replies: 4
    Last Post: 11-06-2004, 07:39 PM
  5. Writing to a file. (PHP)
    By Nasimov in forum Software
    Replies: 3
    Last Post: 04-05-2004, 08:20 PM

Posting Permissions

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