note 84381 added to function.readdir
| From: | MetaNull at osu1 dot php dot net | Date: | Fri, 11 Jul 2008 06:20:50 +0000 |
| Subject: | note 84381 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-141394@lists.php.net to get a copy of this message | ||
A simple directory browser... that handles the windows charset in filenames (it should work for
every iso-8859-1 characters).
<?php
$basepath = realpath("./pub/"); // Root directory
$path = realpath($basepath.$_GET["path"]); // Requested path
$relativepath = "./".substr_replace( $path, "", 0, strlen( $basepath ) );
if( "/" == substr( $relativepath, -1 )) { // Remove the trailing slash
$relativepath = substr( $relativepath, 0, -1 );
}
$dh = opendir( $path );
while( false !== ($file = readdir( $dh ))) {
if("." == $file) {continue;}
// converts the filename to utf8
$file_utf8 = iconv( "iso-8859-1", "utf-8", $file );
// encode the path ('path' part: already utf8; 'filename' part: still
iso-8859-1)
$link = str_replace( "%2F", "/", rawurlencode( "{$relativepath}/"
)) . rawurlencode( utf8_decode( "{$file_utf8}" ));
if( is_dir( "{$path}/{$file}" )) {
echo "<a
href=\"?path={$link}&\">{$file_utf8}</a><br/>"
} else {
echo "<a href=\"{$link}&\">{$file_utf8}</a><br/>"
}
}
}
?>
----
Server IP: 193.190.67.10
Probable Submitter: 85.201.5.129
----
Manual Page -- http://www.php.net/manual/en/function.readdir.php
Edit -- https://master.php.net/note/edit/84381
Del: integrated -- https://master.php.net/note/delete/84381/integrated
Del: useless -- https://master.php.net/note/delete/84381/useless
Del: bad code -- https://master.php.net/note/delete/84381/bad+code
Del: spam -- https://master.php.net/note/delete/84381/spam
Del: non-english -- https://master.php.net/note/delete/84381/non-english
Del: in docs -- https://master.php.net/note/delete/84381/in+docs
Del: other reasons-- https://master.php.net/note/delete/84381
Reject -- https://master.php.net/note/reject/84381
Search -- https://master.php.net/manage/user-notes.php