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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.