Simple File Editor

'; return; }elseif($_POST['password'] == $password && $_SESSION['password'] != $password){ //If password is present but cookie has not been set $_SESSION['password'] = $password; } } //You should not have to change anything below this line. //IF browser does not send a POST request (ie: if open/save has not been //pressed) then display the form and the list of files. if(!$_POST['open'] && !$_POST['save']){ //if ($_SERVER['REQUEST_METHOD'] != 'POST'){ //If filedir is readable do... if (is_readable($filedir)) { ?> Simple File Editor

Simple File Editor

We are in: "; echo "
"; echo getcwd(); echo "

"; //Continue page below. //INFO for below: Select "name" is variable name. Option value is variable //"value". ?>

Please choose a file to open:



Simple File Editor: ERROR!

Simple File Editor: ERROR!

Could not open directory!!
Permissions Problem??

"; } } /////////////////////////////////////////////////////////////////// //If the open button has been pressed //////////////////////////////////////////////////////////////////// else if (isset($_POST['open'])){ //If the file can be opened and is writable do.... //This should not be needed because files that aren't writable should //have never been shown in the selection box. if (is_writable($_POST["the_file"])) { //Start page //INFO for below: Since variable data is not saved across multiple //form posts-- we must create a hidden input box with the same value as the //select box on the previous form. That way the 3rd and final form (ie: the //saving process) can use the same variable as the first form (read: write to //the file you choose in the select box.) ?> Simple File Editor: File Opened

Simple File Editor: File Opened

" /> We are working on: "; echo "
"; //Get previously posted select box data echo $_POST["the_file"]; echo "

"; //Continue page below. ?>
" in them. If this was not was not here and you tried to edit a file with in it all of your code up to would be in this editing forms textarea and everything after would be executed/displayed. This is very confusing, but if you look at the code in this file and then think about it a bit, you will understand what it does.*/ //Do a case insensitive search for in the $current_data string. //replace it with [/textarea]. //This means when you are editing files that contain the editing //box will show [/textarea] instead of the tag. Do not be //alarmed by this. Do NOT change or remove this tag, it will be converted back //to in the saving process. If for some reason this does not work //for you, or if you know a better way to go about doing this please contact //me. //The following code was contributed by anoldman.com. Thanks for modernizing //and dealing with this issue in a more logical fashion Ken! //$current_data = eregi_replace("", "", $current_data); $current_data = preg_replace( "!]+)>(.*?)!is", "[textarea\\1]\\2[/textarea]", $current_data ); $current_data = preg_replace( "/&([a-z\d]{2,7}|#\d{2,5});/i", "&$1;", $current_data ); //Echo the data from the file echo $current_data; //Close the file fclose($file2open); //Continue page below. ?>
Simple File Editor: ERROR!

Simple File Editor: ERROR!

Could not open file!!
Permissions Problem??

"; } } /////////////////////////////////////////////////////// //If save button has been pushed.... ////////////////////////////////////////////////////// else if (isset($_POST['save'])){ //If the file can be opened and is writable do.... //This should not be needed because files that aren't writable should //have never been shown in the selection box. And should not have been opened //on the previous page. if (is_writable($_POST["the_file2"])) { //Get variable data for the file we are working with from the hidden input box //in the previous form. Then open it. $file2ed = fopen($_POST["the_file2"], "w+"); //Dirty hack part 2. Copy all of the data in the previous forms //editing textarea to the variable $data_to_save. $data_to_save = $_POST["updatedfile"]; //Do the opposite of above. This time convert the [/textarea] tag you //see in the editing form back to its proper tag so when your files //are saved the forms on them will still look/work right. #$data_to_save = eregi_replace("", "", $data_to_save); //The following code was contributed by anoldman.com. Thanks for modernizing //and dealing with this issue in a more logical fashion Ken! $data_to_save = preg_replace( "!\[textarea([^\]]+)\](.*?)\[/textarea\]!is", "\\2", $data_to_save ); //Remove any slashes that may be added do to " ' " s. Thats a single tick, btw. //NOTE: If you want to work on files that have slashes in them, comment out the //line below. $data_to_save = stripslashes($data_to_save); //Get the data to write from the previously posted text area, plus all the //processing we did on it above. Write the changes to the file. if (fwrite($file2ed,$data_to_save)) { //If write is successful show success page. echo " Simple File Editor: File Saved

Simple File Editor: File Saved

File saved.
Click here to go back to the editor.

"; //Close file fclose($file2ed); } else { //If write fails show failure page echo " Simple File Editor: ERROR!

Simple File Editor: ERROR!

File NOT saved!!
Permissions Problem??
Click here to go back to the editor.

"; //Close file fclose($file2ed); } } else { //If file can't be opened complain echo " Simple File Editor: ERROR!

Simple File Editor: ERROR!

File NOT saved!!
Permissions Problem??

"; } } ?>