php : ONLY a few scripts to list files in a folder
Sometimes, for the most varied reasons, you want to list only a few files in a folder, and it can not be, not known, or you do not want to use the htaccess file..
Is possible to use a script (for example, I used here to show ONLY the files that begin with the letters “amsn”) in php, that, suitably configured by setting the string $list identifying which are the initials of the file to be displayed, do this without any particular problems.
Here is the code:
$dir_name = "/PATH/TO; $list = "amsn"; $dir = opendir($dir_name); $files = array(); while($file_name = readdir($you)) { if ((strpos($file_name, $list) !== False) && (strpos($file_name, $list) === 0)) { if(($file_name != ".") && ($file_name != "..")) { $files[] = $ File_name; } } } closedir($you); sort($files); reset($files); foreach($files as $ file) { echo "<LI>$File</LI>"; }
Obviously in $ dir_name must show the folder that contains the files you want to list, with absolute path.
E'quasi goes without saying that this script allows you to do something vaguely similar to using. Htaccess even on a Windows hosting.
Cute and useful, not?