note 70779 added to function.scandir

From: Date: Fri, 27 Oct 2006 16:54:48 +0000
Subject: note 70779 added to function.scandir
Groups: php.notes 
Request: Send a blank email to php-notes+get-119186@lists.php.net to get a copy of this message
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>'; ?> ---- Server IP: 216.194.113.175 Probable Submitter: 66.32.105.32 ---- Manual Page -- http://www.php.net/manual/en/function.scandir.php Edit -- https://master.php.net/note/edit/70779 Del: integrated -- https://master.php.net/note/delete/70779/integrated Del: useless -- https://master.php.net/note/delete/70779/useless Del: bad code -- https://master.php.net/note/delete/70779/bad+code Del: spam -- https://master.php.net/note/delete/70779/spam Del: non-english -- https://master.php.net/note/delete/70779/non-english Del: in docs -- https://master.php.net/note/delete/70779/in+docs Del: other reasons-- https://master.php.net/note/delete/70779 Reject -- https://master.php.net/note/reject/70779 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#119186) next »