If you for some reason would like to display files in a directory on the web server there is an easy way to do this. You might for example like to display all images in a directory in a select box on a web page.
<?php // Set folder $folder = "images/";
// And get a handle to it $handle = opendir($folder);
// Create an array containing the files in the current directory: while ($file = readdir($handle)) { $files[] = $file; } closedir($handle); sort($files);
// Print the file names print "<select name='imageNames'>"; Print "<option value='Choose image'>Choose image</option>";
// Loop through array foreach ($files as $file) { // Don't display "." or ".." if (($file != ".") And ($file != "..")) { print sprintf("<option value='images/%s'>%s</option>", $file, $file); } } print "</select>"; ?> |
If you would like to be more specific on which files not to display (the if-statement in the for-loop) you can for example use function 'substr'. In the following example files that begin with "_x" will not be displayed.
| (substr($file, 0, 3) != "_x") |