i want to write a page that will traverse a specified directory.... and get all the files in that directory...
in my case the directory will only contain images and display the images with their links...
something like this
How to Do it
p.s. the directory will not be user input.. it will be same directory always...
use readdir
You could also try the glob function:
I would start off by creating a recursive function:
The $dir param needs to be in the following format: "/path/" or "/path/to/files/"
Basically, just don't include the server root, because i have already done that below using $_SERVER['DOCUMENT_ROOT'].
So, in the end just call the recurseDir function we just made in your code once, and it will traverse any sub folders and output the image with the link under it.
You'll want to use the scandir function to walk the list of files in the directory.
Hi you can use DirectoryIterator
If you want to pass directories recursively: http://php.net/manual/en/class.recursivedirectoryiterator.php