I got a page that loads html code from a text file into an textarea and I need to be able to save the contents of it using a script.
I'm using a PHP script to load the code from a file and echo it out to the textarea, but how can I send back the contents to the script and save it either to the same file or to a file with a new name?
I was thinking if getElementById would help me but I'm not sure how.
The load script(it has the ability to delete files too)
// The file hierarchy:
//
//Web root - admin - This file
//         - pages - in here are the page text files
// The variable pagesList is the filename chosen in a dropdown list earlier
$page = $_GET["pagesList"];
$action = $_GET["action"];
//get the path to the page( all pages are in a folder named 'pages')
$filename = dirname(dirname(__FILE__))."/pages/".$page;
if(file_exists($filename) and is_file($filename)){
    //If I want to load a file
    if($action == "open"){
        $f = fopen($filename,"rt");
        $content = fread($f, filesize($filename));
        echo $content;
        @fclose($f);
    //If I want to delete a file
    }elseif($action == "delete" && is_file($filename)){
        //move the working directory to where the file is
        $old = getcwd();
        chdir(dirname(dirname(__FILE__))."/pages/");
        //----
        if(unlink($filename)) 
            echo "File deleted,".$filename;
        else
            echo "Error deleting file!";
        //change back the working directory to where it was
        chdir($old);
    //If I want to save a file
    }elseif($action == "save"){
        if(file_exists($filename)){
            //Unknown script, need help!
        }else{
        }
    }
}    
The textarea is only one line with an include in it:
   <textarea id="html_content" style="width:600;height:200;"><?php include("loader.php") ?></textarea>
To sum it up: I need help getting the contents of an textarea to a script for saving later.
EDIT: Thanks to davidkonrad I just had to add a few POST receives in the script and add file_put_content with the content sent to it.
The problem that arised is that jQuery apparently puts \ before each " or '. That messes up all the html code that is supposed to be clean and valid. I'll have to replace the \" with " somehow, str_replace wont cut it. Any ideas?
EDIT2: Thanks again to davidkonrad that fixed it by using encodeURIComponent(jQuery) clientside and urldecode(PHP) serverside.
 
     
    