note 70466 added to function.readdir
| From: | dot) | Date: | Tue, 17 Oct 2006 22:01:04 +0000 |
| Subject: | note 70466 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-118670@lists.php.net to get a copy of this message | ||
simple script to read directorys and subdirectorys from a specific location and generate direct
links to the file (suitable for picture gallery-listings or something like that)
in the example, the file is called "directory.php" and links to it self back in 2nd line
<?php
echo "<a href=\"directory.php\">..</a><br>";
// startdir (tiefster, erlaubter relativer pfad zum script)
// subdir (aktuelles unterverzeichnis)
// subdir_n (neues unterverzeichnis (ist altes subdir + neues verzeichnis))
// dir (vollstaendiges verzeichnis (startdir + subdir))
$startdir = "rebell.shared/gfx/screenshots/";
$dir = "$startdir$subdir";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false)
{
$filename = $file;
$filetype = filetype($dir . $file);
if ($filename == ".." OR $filename == ".")
{
echo "";
}
elseif ($filetype == "file")
{
echo "<a href=\"$dir$filename\">$filename</a><br>";
}
elseif ($filetype == "dir")
{
$subdir_n = "$subdir$filename/";
echo "<a
href=\"directory.php?subdir=$subdir_n\">$filename</a><br>";
}
}
closedir($dh);
}
}
?>
----
Server IP: 192.35.244.50
Probable Submitter: 83.215.146.135
----
Manual Page -- http://www.php.net/manual/en/function.readdir.php
Edit -- https://master.php.net/note/edit/70466
Del: integrated -- https://master.php.net/note/delete/70466/integrated
Del: useless -- https://master.php.net/note/delete/70466/useless
Del: bad code -- https://master.php.net/note/delete/70466/bad+code
Del: spam -- https://master.php.net/note/delete/70466/spam
Del: non-english -- https://master.php.net/note/delete/70466/non-english
Del: in docs -- https://master.php.net/note/delete/70466/in+docs
Del: other reasons-- https://master.php.net/note/delete/70466
Reject -- https://master.php.net/note/reject/70466
Search -- https://master.php.net/manage/user-notes.php