Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- try {
- $dir = new DirectoryIterator( $_GET['path'] );
- $items = array();
- foreach ( $dir as $file ) {
- if ( $file->getFilename() === '.' ) {
- continue;
- }
- $items[] = array( !$file->isDir(), $file->getFilename(), realpath( $file->getPathname() ) );
- }
- sort( $items );
- } catch ( UnexpectedValueException $e ) {
- header( 'HTTP/1.0 404 Not Found' );
- $dir = null;
- } catch ( RuntimeException $e ) {
- header( 'HTTP/1.0 400 Invalid Request' );
- $dir = null;
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="ISO-8859-1" />
- <title>Contents of <?php echo htmlspecialchars( $_GET['path'] ); ?></title>
- </head>
- <body>
- <?php if ( $dir === null ) { ?>
- <p>The path "<?php echo htmlspecialchars( $_GET['path'] ); ?>" is invalid.</p>
- <?php } else { ?>
- <h1>Directory Listing for <?php echo htmlspecialchars( $_GET['path'] ); ?></h1>
- <ul>
- <?php
- foreach ( $items as $item ) {
- if ( !$item[0] ) {
- echo "<li><a href='?path=$item[2]'><u>" .
- htmlspecialchars( $item[1] ) .
- '</u></a></li>';
- } else {
- echo '<li>' . htmlspecialchars( $item[1] ) . '</li>';
- }
- }
- ?>
- </ul>
- <?php } ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement