<tr>
<td>Seleziona Categoria</td>
<td><?php echo "<select onchange=\"document.location.href = '" . $_SERVER['PHP_SELF'] . "?cat=' + this.value;\" name=\"cat\">";?>
<option selected="selected" value="">Seleziona</option>
<?php
$result = $db->query("SELECT * FROM foto_categorie");
while($row = mysqli_fetch_array($result))
{
$_cat= $row['titolo'];
$id = $row['id'];
?>
<option value="<?php echo $id; ?>|<?php echo $_cat; ?>" ><?php echo $_cat; ?></option>
<?php
}
?>
</select></td>
</tr>
<tr><tr>
<td>Seleziona Foto</td>
<td><?php
// open the current directory
$pieces = explode("|", addslashes($_GET["cat"]));
$dhandle = opendir('../public/photo/'.$pieces[1].'');
// define an array to hold the files
$files = array();
if ($dhandle) {
// loop through all of the files
while (false !== ($fname = readdir($dhandle))) {
// if the file is not this file, and does not start with a '.' or '..',
// then store it for later display
if (($fname != '.') && ($fname != '..') &&
($fname != basename($_SERVER['PHP_SELF']))) {
// store the filename
$files[] = (is_dir( "./$fname" )) ? "(Dir) {$fname}" : $fname;
}
}
// close the directory
closedir($dhandle);
}
echo "<select name=\"file\">\n";
// Now loop through the files, echoing out a new select option for each one
foreach( $files as $fname )
{
echo "<option>{$fname}</option>\n";
}
echo "</select>\n";
?></td>
</tr>