Reply to Re: Selecting files from server with php

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация