Selecting files from server with php

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
MarkHowardJr [ Fr, 01 Februar 2008 18:49 ] [ ID #1922038 ]

Re: Selecting files from server with php

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... [at] 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
petersprc [ Fr, 01 Februar 2008 21:34 ] [ ID #1922052 ]
PHP » comp.lang.php » Selecting files from server with php

Vorheriges Thema: 10 Reasons Why PHP is Better than ASP
Nächstes Thema: How to get a JPG image from a PDF?