/ Published in: PHP
Loops through all files of a certain extension in the specified directory. Can be used to list all images in a given directory.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php $root = $_SERVER["DOCUMENT_ROOT"]; $path = "/NCCDC/test/docs"; $iterator = new DirectoryIterator($root.$path); /* See php documentation on iterator */ foreach ($iterator as $fileinfo) { if ($fileinfo->isFile()) { $path = $fileinfo->getPathname(); $filename = $fileinfo->getFilename(); /*filename like 'picture1.jpg' */ $ext = $info['extension']; /* extension like 'jpg' */ /* Test to see if extension is allowed */ echo "<a href='$path'>$filename_noext</a><br/> \n"; } } } ?>