Re: hrm.....array question
| From: | Daniel Convissor | Date: | Fri, 06 Oct 2000 04:42:15 +0000 |
| Subject: | Re: hrm.....array question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-18833@lists.php.net to get a copy of this message | ||
Hey Kurth:
> wondering - how would i go about having a script do a ls listing of a
> dir...then return all the entries as links.....then when you click on the
> link you are taken to that dir...then the process is repeated.....but
> instead of links...the files are displayed...like a photo album.....
The script below lists the files and directories. You can modify this script
as you see fit. For instance, to make all the images display, you can change
it from <a href's to <img src's.
--Dan
# Open a directory handle:
$DirHandle=opendir('.');
# Go through each element in the handle one at a time
# assign the current element to the $FileHandle variable
# check the first three characters in $FileHandle:
while ($FileName = readdir($DirHandle)) {
switch (substr($FileName,0,3)) {
case ".":
case "..":
# System files, etc, so ignore them
break;
default:
# This is a file we want to list, so stick it into the array
$i++;
if (is_dir($FileName)) {
$FileList[$i] = "$FileName/";
} else {
$FileList[$i] = $FileName;
}
break;
}
}
# Sort the list alphabetically:
asort($FileList);
# You can now return an alphabetized list of all files fitting
# the criteria above:
echo "<ul>";
for(reset($FileList); $key = key($FileList); next($FileList)) {
echo "<li><a
href=\"$FileList[$key]\">$FileList[$key]</a></li>\n";
}
echo "</ul>";
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
More than just answers. Solutions. (SM)
http://www.analysisandsolutions.com/
4015 7 Av #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409