blueman378 Posted November 30, 2007 Share Posted November 30, 2007 hi there, im looking to grab a very simple file editor, all it has to do is open a said file (in text format) and read the contents into a text area, then i simple make the changes and click save and it saves them to that file, e.g ___________________________ |Drop down box to open set files| _____________________________________ |Text area for file to be read to | | | |____________________________________| ___________ |save button| cheers Quote Link to comment Share on other sites More sharing options...
trq Posted November 30, 2007 Share Posted November 30, 2007 im looking to grab a very simple file editor I think you miss the point of this forum. We help you with problems in your code. If you need a script built for you post your request in the Freelance board. Please read the Freelance Guidlelines before however doing so. Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted November 30, 2007 Share Posted November 30, 2007 There are a fair amount of tutorials out there that you can adapt: You could try something like this, (this hasn't been debugged so may need some tweaking) <?php if ($_POST['Submit12'] == "Submit") { $file_name = "textfile.txt"; $open_file = fopen($file_name, "a+"); $file_contents= $_POST['title'] . '|' . $_POST['news']; fwrite($open_file, $file_contents); fclose($open_file); echo "Form data successfully written to file"; } ?> <form id="formname" name="formname" method="post" action=""> Title:</span> <input type="text" name="title" /> <textarea name="news" cols="85" rows="15" id="news"> </textarea> <label> <input type="submit" name="Submit" value="Submit" /> </label> </form> Quote Link to comment Share on other sites More sharing options...
blueman378 Posted November 30, 2007 Author Share Posted November 30, 2007 yeah sory i should have posted what im currently using: <center><?php $loadcontent = "textfile.txt"; $fp = @fopen($loadcontent, "r"); $loadcontent = fread($fp, filesize($loadcontent)); $loadcontent = htmlspecialchars($loadcontent); fclose($fp); ?> <form method=post action="<?=$_SERVER['PHP_SELF']?>"> <textarea name="savecontent" cols="25" rows="10"><?=$loadcontent?></textarea> <br> <input type="submit" name="save_file" value="Save"> </form> <?php if($save_file) { $savecontent = stripslashes($savecontent); $fp = @fopen($loadcontent, "w"); if ($fp) { fwrite($fp, $savecontent); fclose($fp); } } ?> </center> this works im just looking for a way to have a dropdown box which contains a list of set files eg : file1.txt extra/file2.tx links.txt and then when the user selects it it writes that value to $loadcontent and refreshes the page so it loads that, i really have no idea where to start for this ( i possibly could but its 11 at night and i cant really think lol thanks for any help, Quote Link to comment Share on other sites More sharing options...
blueman378 Posted November 30, 2007 Author Share Posted November 30, 2007 hi guys, thanks 4 ur help, i got this solved heres the code, it has a form which is displayed if a page has not been selected, if page has been selected then it refreshes and loads the editor, thanks Quote Link to comment Share on other sites More sharing options...
blueman378 Posted November 30, 2007 Author Share Posted November 30, 2007 sorry, <?php include("../include/session.php"); /** * User not an administrator, redirect to main page * automatically. */ if(!$session->isAdmin()){ ?> <center><font color="red"<h3><i>ERROR</i>: Access Denied</h3></font> Back to [<a href="../index.php">Main Page</a>]</center><?php } else{ ?> <center> <?php if (!isset($_POST['submit'])) { ?> <form method="post" action="<?php echo $PHP_SELF;?>"> Select a file to edit:<br /> <select name="file"> <option value="../links.txt">Site Links</option> <option value="../mainintro.txt">Main Intro</option> </select> <input type="submit" value="submit" name="submit"><br /> </form> <?php } else { $loadcontent = $_POST["file"];; $fp = @fopen($loadcontent, "r"); $loadcontent = fread($fp, filesize($loadcontent)); $loadcontent = htmlspecialchars($loadcontent); fclose($fp); ?> <form method="post" action="<?php echo $PHP_SELF;?>"> Select a file to edit:<br /> <select name="file"> <option value="../links.txt">Site Links</option> <option value="../mainintro.txt">Main Intro</option> </select> <input type="submit" value="submit" name="submit"><br /> </form> <form method=post action="<?=$_SERVER['PHP_SELF']?>"> <textarea name="savecontent" cols="70" rows="30"><?=$loadcontent?></textarea> <br> <input type="submit" name="save_file" value="Save"> </form> <?php if($save_file) { $savecontent = stripslashes($savecontent); $fp = @fopen($loadcontent, "w"); if ($fp) { fwrite($fp, $savecontent); fclose($fp); } } } ?> <?php } ?> </center> there is some extra code there simply to protect the page from someone who is not a admin using it Quote Link to comment Share on other sites More sharing options...
blueman378 Posted November 30, 2007 Author Share Posted November 30, 2007 ok heres the code <?php /** * User not an administrator, redirect to main page * automatically. */ if(!$session->isAdmin()){ ?> <center><font color="red"><h3><i>ERROR</i>: Access Denied</h3></font> Back to [<a href="../index.php">Main Page</a>]</center><?php } else{ ?> <center> <?php if (!isset($_POST['submit'])) { ?> <form method="post" action="<?php echo $PHP_SELF;?>"> Select a file to edit:<br /> <select name="file"> <option value="../links.txt">Site Links</option> <option value="../mainintro.txt">Main Intro</option> <option value="adminlinks.txt">Admin Links</option> </select> <input type="submit" value="submit" name="submit"><br /> </form> <?php } else { $loadcontent = $_POST["file"];; $fp = @fopen($loadcontent, "r"); $loadcontent = fread($fp, filesize($loadcontent)); $loadcontent = htmlspecialchars($loadcontent); fclose($fp); ?> <form method="post" action="<?php echo $PHP_SELF;?>"> Select a file to edit:<br /> <select name="file"> <option value="../links.txt">Site Links</option> <option value="../mainintro.txt">Main Intro</option> <option value="adminlinks.txt">Admin Links</option> </select> <input type="submit" value="submit" name="submit"><br /> </form> <form method=post action="<?=$_SERVER['PHP_SELF']?>"> <textarea name="savecontent" cols="70" rows="30"><?=$loadcontent?></textarea> <br> <input type="submit" name="save_file" value="Save"> </form> <?php if($save_file) { $savecontent = stripslashes($savecontent); $fp = @fopen($loadcontent, "w"); if ($fp) { fwrite($fp, $savecontent); fclose($fp); } } } ?> <?php } ?> now it opens the files alright, however the problem is that it doesnt save to the file when you click save any ideas why? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.