Advertisement
parent5446

Untitled

Jun 29th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. <?php
  2.  
  3. try {
  4.     $dir = new DirectoryIterator( $_GET['path'] );
  5.     $items = array();
  6.     foreach ( $dir as $file ) {
  7.         if ( $file->getFilename() === '.' ) {
  8.             continue;
  9.         }
  10.         $items[] = array( !$file->isDir(), $file->getFilename(), realpath( $file->getPathname() ) );
  11.     }
  12.     sort( $items );
  13. } catch ( UnexpectedValueException $e ) {
  14.     header( 'HTTP/1.0 404 Not Found' );
  15.     $dir = null;
  16. } catch ( RuntimeException $e ) {
  17.     header( 'HTTP/1.0 400 Invalid Request' );
  18.     $dir = null;
  19. }
  20.  
  21. ?>
  22. <!DOCTYPE html>
  23. <html>
  24.     <head>
  25.         <meta charset="ISO-8859-1" />
  26.         <title>Contents of <?php echo htmlspecialchars( $_GET['path'] ); ?></title>
  27.     </head>
  28.     <body>
  29.         <?php if ( $dir === null ) { ?>
  30.             <p>The path "<?php echo htmlspecialchars( $_GET['path'] ); ?>" is invalid.</p>
  31.         <?php } else { ?>
  32.             <h1>Directory Listing for <?php echo htmlspecialchars( $_GET['path'] ); ?></h1>
  33.             <ul>
  34.                 <?php
  35.                     foreach ( $items as $item ) {
  36.                         if ( !$item[0] ) {
  37.                             echo "<li><a href='?path=$item[2]'><u>" .
  38.                                 htmlspecialchars( $item[1] ) .
  39.                                 '</u></a></li>';
  40.                         } else {
  41.                             echo '<li>' . htmlspecialchars( $item[1] ) . '</li>';
  42.                         }
  43.                     }
  44.                 ?>
  45.             </ul>
  46.         <?php } ?>
  47.     </body>
  48. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement