note 72793 added to function.readdir
| From: | mike at mihalism dot com | Date: | Thu, 01 Feb 2007 22:30:42 +0000 |
| Subject: | note 72793 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-122493@lists.php.net to get a copy of this message | ||
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>";
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 68.106.90.12
----
Manual Page -- http://www.php.net/manual/en/function.readdir.php
Edit -- https://master.php.net/note/edit/72793
Del: integrated -- https://master.php.net/note/delete/72793/integrated
Del: useless -- https://master.php.net/note/delete/72793/useless
Del: bad code -- https://master.php.net/note/delete/72793/bad+code
Del: spam -- https://master.php.net/note/delete/72793/spam
Del: non-english -- https://master.php.net/note/delete/72793/non-english
Del: in docs -- https://master.php.net/note/delete/72793/in+docs
Del: other reasons-- https://master.php.net/note/delete/72793
Reject -- https://master.php.net/note/reject/72793
Search -- https://master.php.net/manage/user-notes.php