Get filenames from a specified folder

Hey guys! Could you help me with a problem I`ve been having lately.

I`m building website with an image gallery in it. Images for the gallery are grouped in different folders on a server. There are folders with images and thumbs folders inside those for thumbnails. Thumbnail names are exactly the same as original image names. What I want to do is to make a loop that will extract filenames from the specified folder and put them as a link on thumbnail. So in the end result I would get all the thumbnails displayed on the page and when I click on them it would open the original image.

Is it possible to do with php? Im really quite new to php and dont know much things yet.

They are just subfolders (gallery1, gallery2, gallery3) of the folder called “gallery”.

Thanks everybody for the answers. Will try to write the function. It will be then my first in real world applicable function I have written myself in php :smiley:

I use glob

1/ Search the folder for all images - I restrict to jpg or JPG as that is all my images will be.

2/ I then have an array containing all the large images and the thumbnails.

3/ In my case the thumbnails are prefixed with th_ and so I do a loop and if the file name starts with a th_ it is displayed in a table or using css.

4/ At the same time as the image is displayed the link to the larger image is created - just strip the th_ off the filename.

You could make the above into a function and call it for each folder

Have you got any details about the files stored in a database at all?

No, i don`t think I have. The files are just copied to the ftp folders. Do the files need to be stored in the database in order for php to get to them?

How are the “different folders” structured on your server?

or [fphp]glob[/fphp] :slight_smile:

No.

You can use opendir() and [URL=“http://au2.php.net/manual/en/function.scandir.php”]scandir() to build your loop of thumbnail links.

Do feel free to post your work-in-progress here, if you get stuck or would like to perhaps find “better” (or just different) ways to do the same thing. :slight_smile: