Witam, mam taki skrypt do wyświetlania zdjęć. problem w tym, że chciałbym je posortować aby niedawno dodany element był na szczycie, a nie wiem gdzie dać sortowanie, oraz jakie zastosować.
kod:
/* settings */
$image_dir = './zdjecia1/';
$thumb_dir = './min/';
$per_column = 4;
/* step one: read directory, make array of files */
settype($files, 'array');
if ($handle = opendir($thumb_dir)) {
while (false !== ($file = readdir($handle)))
{
if ($file != '.' && $file != '..')
{
array_push($files, $file);
}
}
closedir($handle);
}
natsort($files);
echo '<div style="background-color:grey; width:800px; height:800px; margin:0 auto;" align="center">';
echo '<table><tr><td width="150" valign="top"><p align="center" style="font-size:20px;">Meniu</p>
<a style="margin: 20px 10px 10px 30px;" href="wgraj.php">Dodaj Zdjęcie</a><br />
<a style="margin: 20px 10px 10px 30px;" href="szatan.php">Galeria</a><br />
<a style="margin: 20px 10px 10px 30px;" href="usun.php">Usun zdjecie</a>
</td><td align="center" width="650">';
/* step two: loop through, format gallery */
if(count($files))
{
echo '<p style="text-align:center; font-size:30px;">Oto twoje zdjecia</p><table border="1"><tr>';
foreach($files as $file)
{
@$count++;
echo '<td width="140" align="center" height="120"><a class="photo-link" rel="lightbox[set]" href="',$image_dir,$file,'"><img src="',$thumb_dir,$file,'" style="border: 1px solid black; margin: 5px 5px 5px 5px;" /></a></td>';
if($count % $per_column == 0) { echo '<tr></tr>'; }
}
echo '</tr></table></td></tr></table>';
}
else
{
echo '<p style="text-align:center; font-size:30px;">Brak zdjec w galerii.</p>';
}
echo '</div>';
?>