Jump to content

Editor build help


smokinfish

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/224421-editor-build-help/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/224421-editor-build-help/#findComment-1159323
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.