I have a text area that displays the contents of an external source file for editing using tinymce.
I would like to have a dropdown list so I can select other external sources to load into the textarea for editing.
How can I accomplish this?
I'm not asking for someone to do this for me but rather to help me into the right direction.
"Give a man a fish and he will eat for a day. Teach a man to fish and he will eat for the rest of his life"
I have a text area that displays the contents of an external source file for editing using tinymce.
I would like to have a dropdown list so I can select other external sources to load into the textarea for editing. How can I accomplish this?
Probably the best place to ask a question like this is in the TinyMCE Support Forum, where it's probably been answered many, many times. Apparently you use one of the built-in commands:
/* Change $myFile = "data.php"; to ... */
$myFile = $_POST['source'];
if (is_file($myFile))
/* File is good, try to read it */
else
/* Use a default file or crash */
The Following User Says Thank You to wirehopper For This Useful Post:
Thank you so much for your help. It makes me feel good that there are still people in the world that are kind to others. You never had to help me out but you did.
I will take what you have shown me and try to apply it to when I have to save the file.
Right now when you click the save button it saves whatever is loaded into the textarea to data.php. I will need to be able to save whatever is in the textarea to the file that was opened in the textarea.
What I meant by me making things overly complicated was I now have two dropdown boxes, one for opening and one for saving. I would like to simplify it to one dropdown box that opens the file and remembers what file is open so when I click save it simply saves to the file that I opened from the dropdown box.
Here is the complete code.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>editor</title>
</head>
<body>
<?php
$saving = $_REQUEST['saving'];
if ($saving == 1){
$data = $_POST['data'];
if (isset($_POST['source']))
$file = $_POST['source'];
else
$file='instructions.php'; /* I will have to fix this to save to the file loaded somehow*/
$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!");
fclose($fp);
$theMessage = "Saved!";
}
?>
<?php
if (isset($_POST['source']))
$myFile = $_POST['source'];
else
$myFile='instructions.php';
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
?>
<div style="height:25px">
<?php echo $theMessage; ?>
</div>
<form name="myForm" method="post" action="editor.php">
<select name="source" size="1">
<option>data.php</option>
<option>data2.php</option>
</select>
<input type="submit" name="submit" value="Choose File To Edit">
</form>
<form action="editor.php?saving=1" method="post" name="form">
<textarea cols="100" name="data" rows="10">
<?php echo $theData;?>
</textarea>
<br><br>
<select name="source" size="1">
<option>data.php</option>
<option>data2.php</option>
</select>
<input type="submit" value="Choose Where To Save">
</form>
</body>
</html>
I thought using a zip file would be easy for you that's why I did it that way.