-2

I'm trying to make a page where I can share pictures. For the time being, I'm not using a database, just uploading them into my htdocs. All of my pictures will be PNG, and saved in a folder called myimages. I want a page to list all of these images, if it's possible. Thanks for the help!

YankueUser
  • 23
  • 4
  • 1
    This question has an answer here https://stackoverflow.com/a/17576567/12232340 –  Feb 23 '20 at 19:10
  • 1
    Does this answer your question? [Pull all images from a specified directory and then display them](https://stackoverflow.com/questions/11903289/pull-all-images-from-a-specified-directory-and-then-display-them) – Graphileon Feb 23 '20 at 19:56

1 Answers1

0

If you want to list all files in a directory, you can use scandir:

$dir = '/your/folder';
$files1 = scandir($dir); //returns an array of file names (strings)

However, if you need to restrict your search to only PNG files, use glob instead:

glob('/your/folder/*.png');

The pattern *.png matches against all file names that end with ".png", and adding the path before that ensures we only get results from inside the specified folder.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Anis R.
  • 6,656
  • 2
  • 15
  • 37