I am trying to display the most recent images added to a portfolio items folder to use as featured images - The code below is doing a good job of getting an image from the specified folder, however it's not displaying the last one to be uploaded… any suggestions?
<?php
$files= glob('./uploads/test/'. $user->id .'/'.$item->id.'/*');
$count = 0;
$user_avatar = '/images/noimage.jpg';
if (!file_exists('./uploads/test/'. $user->id .'/'.$item->id.'/*')) {
$user_avatar = '/images/noimage.jpg';
}
// otherwise continue
foreach ($files as $file) {
$count++;
if ($count > 0 && is_file($file)) {
$user_avatar = $file;
}
}
?>