|
Posted by petersprc on 02/01/08 20:34
Use glob to get the files and onChange to switch:
<select name=file onChange="window.location.href=this.options
[this.selectedIndex].value">
<option value="file.php?file=file1.txt">file1.txt</option>
value="file.php?file=file2.txt">file2.txt</option>
</select>
Script below:
[file.php]
<?
error_reporting(E_ALL | E_STRICT);
$file = isset($_GET['file']) ? $_GET['file'] : false;
// Select box
$sel = '<select name=file style="width: 400px;" onChange=' .
'"window.location.href=this.options' .
"[this.selectedIndex].value\">\n";
$sel .= "<option value=\"#\">-- Select --</option>\n";
$found = false;
$files = glob('*');
foreach ($files as $ent) {
$url = $_SERVER['PHP_SELF'] . '?file=' . urlencode($ent);
$sel .= '<option value="' . htmlentities($url, ENT_QUOTES) .
'"';
if ($ent === $file) {
$sel .= ' selected';
$found = true;
}
$sel .= '>' . htmlentities($ent, ENT_QUOTES) .
"</option>\n";
}
$sel .= "</select>\n";
// File content
$content = '';
if ($found) {
$content = htmlentities(file_get_contents($file),
ENT_QUOTES);
}
?>
<? if ($file !== false && !$found) { ?>
<p>File <?= htmlentities($file, ENT_QUOTES) ?> not found.</p>
<? } ?>
<form action="#">
File<br>
<?= $sel ?><br>
<br>
Content<br>
<textarea cols=40 rows=10 style="width: 400px;">
<?= $content ?>
</textarea><br>
<br>
<input type=submit value=" OK ">
</form>
On Feb 1, 12:49 pm, Dual_b00t <MarkHowar...@gmail.com> wrote:
> Hi i made a little app that opens a html file into fckeditor then
> after edit saves the html file.
>
> I would like to add a drop down list or whatever is best, so i can
> select from files on the server to edit. How would I accomplish this
> task.. in the simplest form since I am a newbie..
>
> Thanks much
Navigation:
[Reply to this message]
|