note 72793 deleted from function.readdir by tularis
| From: | tularis@php.net | Date: | Sun, 13 May 2007 18:58:46 +0000 |
| Subject: | note 72793 deleted from function.readdir by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126496@lists.php.net to get a copy of this message | ||
Note Submitter: mike at mihalism dot com
----
Here is a update to the directory list script.
It still has same features I just made it so if you get no results you will know.
<?php
/*
edit $path to the directory you want to use
edit $file_types to change the file types to show
*/
function file_type($file){
$path_chunks = explode("/", $file);
$thefile = $path_chunks[count($path_chunks) - 1];
$dotpos = strrpos($thefile, ".");
return strtolower(substr($thefile, $dotpos + 1));
}
$file_count = 0;
$path = "files/";
$file_types = array('jpeg', 'jpg', 'ico', 'png',
'gif', 'bmp');
$p = opendir($path);
while (false !== ($filename = readdir($p))) {
$files[] = $filename;
}
sort($files);
foreach ($files as $file) {
$extension = file_type($file);
if($file != '.' && $file != '..' &&
array_search($extension, $file_types) !== false){
$file_count++;
echo '<a
href="'.$path.$file.'">'.$file.'</a> <br/>';
}
}
if($file_count == 0){
echo "<b>No file match your file types</b>";
}
?>