I would like to pull a single image out of the folder ‘upload/’ to display instead of all of them. Is this possible? It doesn’t need to be the same picture all of the time (in fact I would like it to be the most recent). Any help is always appreciated
[php] <?php
$image_dir = 'upload/';
$per_column = 1;
$validExt = array(
'png' => 'image/png',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpg',
'gif' => 'image/gif',
'mp3' => 'audio/mp3',
);
if ($handle = opendir($image_dir)) {
while (false !== ($file = readdir($handle)))
{
$ext = strtolower(substr($file, -3));
if (isset($validExt[$ext]))
{
$stats = stat($image_dir.$file);
$files[$stats['mtime']] = $file;
}
}
closedir($handle);
}
$count = 1;
krsort($files);
$cnt = count($files);
if($cnt)
{
foreach($files as $file)
{
$count;
echo '<a href="' . $image_dir . $file . '" rel="scripts/lightbox" title="' . $file .'" ><li style="list-style-type:none"><img src="' . $image_dir . $file . '" width="300" height="225" title="" /></li></a><caption style="text-align:center"><i>Image pulled from<a href="Upload_Page.php">UPLOAD</a> page</i></caption>'.chr(10);
if($count % $per_column == 0) { echo '<div class="clear"></div>'; }
}
}
else
{
echo 'no pictures yet...';
}
?>[/php]