note 70779 deleted from function.scandir by felipe
| From: | felipe@php.net | Date: | Fri, 29 Aug 2008 23:25:23 +0000 |
| Subject: | note 70779 deleted from function.scandir by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-144002@lists.php.net to get a copy of this message | ||
Note Submitter: reeded2002 at mypacks dot net
----
In response to phpfeedback.e.stevegs, if you want to emulate the page displayed by an absent index
completely I think this is more accurate:
<?php
echo '<h1>Index of /adult/</h1>';
echo '<ul>';
echo '<li><a href="/"> Parent Directory</a></li>';
$dir = scandir('.');
$files = count( $dir );
for ( $i = 0; $i < $files; $i++ )
{
if ( is_file($dir[$i]) )
echo "<li><a
href=\"$dir[$i]\">$dir[$i]</a></li><br>";
if ( is_dir($dir[$i]) )
echo "<li><a
href=\"$dir[$i]\"/>$dir[$i]/</a></li><br>";
}
echo '</ul>';
?>
If the directory happens to be the root you'ld want to leave off the Parent Directory line.
It's easy to apply filters to this. What I'm using filters out filenames of a certain
length, any non-html and non-php files, and also various other files and directories I just
dont' want being shown:
<?php
echo '<h1>Index of /adult/</h1>';
echo '<ul>';
echo '<li><a href="/"> Parent Directory</a></li>';
$dir = scandir('.');
$files = count( $dir );
for ( $i = 0; $i < $files; $i++ )
{
if ( is_file($dir[$i]) && strlen( $dir[$i] ) <= 36 && ( strstr(
strtolower( $dir[$i] ), '.htm' ) || strstr( strtolower( $dir[$i] ), '.html' )
|| strstr( strtolower( $dir[$i] ), '.php' ) ) )
echo "<li><a
href=\"$dir[$i]\">$dir[$i]</a></li><br>";
if ( is_dir($dir[$i]) && $dir[$i] != "." && $dir[$i] !=
".." && $dir[$i] != "adult" )
echo "<li><a
href=\"$dir[$i]\"/>$dir[$i]/</a></li><br>";
}
echo '</ul>';
?>