Gabriel Lindgren
Gabriel Lindgren

Reputation: 100

Show latest images first after being taken from directory

I'm currently working on a project where you can upload an image to a directory and then displaying them on the site. But, the latest image being uploaded is at the bottom and the oldest at the top. Can I reverse this in anyway? Tell me if I am totally on the wrong track. I'm new to php but here is a snippet of where the image from the directory being uploaded:

//upload from folder

$files = glob("images/*.*");
for ($i=0; $i<count($files); $i++)
{
$image = $files[$i];
echo '<img src="'.$image.'"><br>';
}

Thanks in advance!

Upvotes: 0

Views: 50

Answers (2)

Panama Jack
Panama Jack

Reputation: 24448

Try this

$files = glob("images/*.*");
$files = array_reverse($files); 

Upvotes: 1

Sankalp Srivastava
Sankalp Srivastava

Reputation: 392

sorry i can't comment. just wanted to ask that when you are uploading the images, are you saving there details somewhere in the database, if yes, you can save the filename and time of upload in the database and can use the same to retrieve the images with latest time

Upvotes: 0

Related Questions