phpscandir

Read all files in a directory and return a list in php


With scandir i can get the files but they are ugly displayed:

Array ( [0] => . [1] => .. [2] => jan-spaceship.jpg [3] => jan-tychostation.jpg [4] => johan-mars.jpg [5] => mary-132786.jpg [6] => mary-mars.jpg )

What i want is a custom div with the name and maybe even display the image (it are all images). Is that possible with a foreach loop or a for loop?


Solution

  • I found already an anser:

            $fileList = glob('uploads/*');
    
        //Loop through the array that glob returned.
        foreach($fileList as $filename){
           //Simply print them out onto the screen.
           echo $filename, '<br>'; 
        }