smokinfish Posted January 14, 2011 Share Posted January 14, 2011 Hi there, i have a problem regarding a editor that I am building, I am fairly new to php, but this is what i have so far: <?php $dirname = "."; $dir = opendir($dirname); ?> <form action="editor.php" method="POST"> <select> <?php while(false != ($file = readdir($dir))) if (strpos($file, '.php',1)||strpos($file, '.html',1)||strpos($file, '.css',1) ) { { if(($file != ".") and ($file != "..")) { echo("<option><a href='$file'>$file</a></option>"); } }} ?> </select> <input type="submit" value="Submit" /> </form> <br /> <center> <form > <textarea rows="80" cols="130"> <?php include $_POST["$file"]; ?> </textarea> </center> The code produces a drop down list of any html, php or css files in the current directory and I want it to be able to show the selected file from the drop down list in the textarea so that I can edit it, I also am not sure how to save the file, would this be a file write method? any help would really be appreciated as I've been stuck on this issue for hours an its doing my nut in!!! Thanks SF Quote Link to comment https://forums.phpfreaks.com/topic/224421-editor-build-help/ Share on other sites More sharing options...
denno020 Posted January 14, 2011 Share Posted January 14, 2011 You will use $contents = file_get_contents('$fileName') Where $fileName is the full path to the file you want to read (or possibly the path from the location of the script). You then echo $contents into the value part of a text area, and you can go ahead and make your changes. Saving is a matter of passing the edited contents (so the data in the text area) into the function file_put_contents('$fileName','$contents'); I just did a simple google search to find that information, I have never used it before, I simply read the information on php.net and suggested you try it. Search google for the function names if you want more information on them, as well as examples of them being used. Denno Quote Link to comment https://forums.phpfreaks.com/topic/224421-editor-build-help/#findComment-1159323 Share on other sites More sharing options...
smokinfish Posted January 14, 2011 Author Share Posted January 14, 2011 Thanks for that, All I've done for the past 5 hours is google the problem and I still can't get this to work, I'm sure its something to do with the $file as I think its empty? The reason for this is when I echo the $file, it returns nothing..... Quote Link to comment https://forums.phpfreaks.com/topic/224421-editor-build-help/#findComment-1159329 Share on other sites More sharing options...
denno020 Posted January 14, 2011 Share Posted January 14, 2011 in the sample code I gave above, you wouldn't echo $fileName, you would echo $contents... Denno Quote Link to comment https://forums.phpfreaks.com/topic/224421-editor-build-help/#findComment-1159333 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.