Ho trovato in internet questo codice:
Codice PHP:
<?
$handle=opendir('immagini');
$pics=array();
$count=0;
while (($file = readdir($handle))!==false) {
if (substr($file,-4) == ".jpg" || substr($file,-4) == ".gif" || substr($file,-4) == ".png" || substr($file,-4) == ".JPG" || substr($file,-4) == ".GIF" || substr($file,-4) == ".PNG"){
if (substr($file,0,3) == "tn_"){
$pics[$count] = $file;
$count++;
}
}
}
closedir($handle);
sort($pics);
reset($pics);
echo '<div align="center"><table width="100%" border=0 cellpadding=0 cellspacing=0>';
echo "<tr>";
$frac=ceil(100/$colonne);
if (($frac*$colonne)>100) $frac--;
for ($f=0;$f<=sizeof($pics)-1;$f++){ // 2
$isbr = strpos((($f)/$colonne),".");
if (!$isbr && ($f!=0)){echo "</tr>\n<tr><td colspan=$colonne><br></td></tr>\n<tr>\n";}
if ($f==0){echo "\n";}
echo '<td width="'.$frac.'%" valign="middle" align="center">';
echo'<a href="immagini/'.substr($pics[$f],3).'" target="_blank" title="'.$lang_ingrandisci.'">';
echo'<img src="immagini/'.$pics[$f].'" border=0></a><br><input type="radio" name="immagine" value="'.substr($pics[$f],3).'">';
echo '</td>';
echo"\n";
}
// close table
echo '</tr></table></div>';
?>
Se voglio che dopo avermi letto dalla directory "icone" tutte le immagini gif me li metta in ordine di nome (le immagini stanno numerate per 001.gif, 002.gif, ecc) in questa tabella come dovrei fare?
Codice HTML:
<table border="0" width="100%">
<tr>
<td style="width:256">
<p style="text-align:center">
</p></td>
<td style="width:256">
<p style="text-align:center">
</p></td>
<td style="width:256">
<p style="text-align:center">
</p></td>
</tr>
<tr>
<td style="width:256" align="center">
</td>
<td style="width:256" align="center">
</td>
<td style="width:256" align="center">
</td>
</tr>
<tr>
<td style="width:256" align="center">
</td>
<td style="width:256" align="center">
</td>
<td style="width:256" align="center">
</td>
</tr>
<tr>
<td style="width:256" align="center">
</td>
<td style="width:256" align="center">
</td>
<td style="width:256" align="center">
</td>
</tr>
<tr>
<td style="width:256" align="center">
</td>
<td style="width:256" align="center">
</td>
<td style="width:256" align="center">
</td>
</tr>
<tr>
<td style="width:256" align="center">
</td>
<td style="width:256" align="center">
</td>
<td style="width:256" align="center">
</td>
</tr>
<tr>
<td style="width:256" align="center">
</td>
<td style="width:256" align="center">
</td>
<td style="width:256" align="center">
</td>
</tr>
<tr>
<td style="width:256" align="center">
</td>
<td style="width:256" align="center">
</td>
<td style="width:256" align="center">
</td>
</tr>
<tr>
<td style="width:256" align="center">
</td>
<td style="width:256" align="center">
</td>
<td style="width:256" align="center">
</td>
</tr>
<tr>
<td style="width:256" align="center">
</td>
<td style="width:256" align="center">
</td>
<td style="width:256" align="center">
</td>
</tr>
</table>