PHP gevorderde |
|
Dit script had ik ooit eens geschreven:
<?php
if ( !isset($path) || $path == "" ) {
$path = ".";
}
print "<p>Current path: <b>".$path."</b></p>";
print "<table border=0>";
$d_arr = array(); $d = 0;
$f_arr = array(); $f = 0;
if( is_dir( $path ) ) {
if( $handle = opendir( $path ) ) {
while( false !== ( $file = readdir( $handle ) ) ) {
if( $file != "." && $file != ".." && $file[0] != "." ) {
if( is_dir( $path . "/" . $file ) )
$d_arr[$d++] = $file;
else
$f_arr[$f++] = $file;
}
}
}
}
if( is_dir( $handle ) ) closedir( $handle );
asort( $d_arr ); reset( $d_arr );
asort( $f_arr ); reset( $f_arr );
$d_prev = substr( $path, 0, ( strrpos( dirname( $path . "/." ), "/" ) ) );
print "<tr><td><a href=\"?action=go&path=".$path."\"><img src=\"..\\..\\images\\refresh.gif\" border=0></a></td><td><a href=\"?action=go&path=".$path."\">Refresh</a><br /></td></tr>";
print "<tr><td><a href=\"?action=go&path=".$d_prev."\"><img src=\"..\\..\\images\\up.gif\" border=0></a></td><td><a href=\"?action=go&path=".$d_prev."\">Parent Directory</a><br /></td></tr>";
# mappenlijst
for( $i=0; $i < count( $d_arr ); $i++ ) {
print "<tr><td><a href=\"?action=go&path=" . $path . "/" . $d_arr[$i] . "\"><img border=0 src=\"..\\..\\images\\folder.gif\"></a></td><td>";
print "<a href=\"?action=go&path=" . $path . "/" . $d_arr[$i] . "\">" . $d_arr[$i] . "</a>/<br />";
print "</td></tr>";
}
# bestandenlijst
for( $i=0; $i < count( $f_arr ); $i++ ) {
print "<tr><td><img src=\"..\\..\\images\\text.gif\"></td><td>";
print $f_arr[$i];
print "</td>";
print "<td>";
if( filesize( $path . "/" . $f_arr[$i] ) >= 1024 ) {
# grootte in kilobytes
print " " . round( filesize( $path . "/" . $f_arr[$i] ) / 1024, 1 ) . " KB<br />";
} elseif( filesize( $path . "/" . $f_arr[$i] ) >= 1048576 ) {
# grootte in megabytes
print " " . round( filesize( $path . "/" . $f_arr[$i] ) / 1024 / 1024, 1 ) . " MB<br />";
} else {
# grootte in bytes
print " " . filesize( $path . "/" . $f_arr[$i] ) . " bytes<br />";
}
print "</td></tr>";
?>
<?php if ( !isset($path) || $path == "" ) { $path = "."; } print "<p>Current path: <b>".$path."</b></p>"; print "<table border=0>"; $d_arr = array(); $d = 0; $f_arr = array(); $f = 0; while( false !== ( $file = readdir( $handle ) ) ) { if( $file != "." && $file != ".." && $file[0] != "." ) { if( is_dir( $path . "/" . $file ) ) $d_arr[$d++] = $file; else $f_arr[$f++] = $file; } } } } print "<tr><td><a href=\"?action=go&path=".$path."\"><img src=\"..\\..\\images\\refresh.gif\" border=0></a></td><td><a href=\"?action=go&path=".$path."\">Refresh</a><br /></td></tr>"; print "<tr><td><a href=\"?action=go&path=".$d_prev."\"><img src=\"..\\..\\images\\up.gif\" border=0></a></td><td><a href=\"?action=go&path=".$d_prev."\">Parent Directory</a><br /></td></tr>"; # mappenlijst for( $i=0; $i < count( $d_arr ); $i++ ) { print "<tr><td><a href=\"?action=go&path=" . $path . "/" . $d_arr[$i] . "\"><img border=0 src=\"..\\..\\images\\folder.gif\"></a></td><td>"; print "<a href=\"?action=go&path=" . $path . "/" . $d_arr[$i] . "\">" . $d_arr[$i] . "</a>/<br />"; } # bestandenlijst for( $i=0; $i < count( $f_arr ); $i++ ) { print "<tr><td><img src=\"..\\..\\images\\text.gif\"></td><td>"; if( filesize( $path . "/" . $f_arr[$i] ) >= 1024 ) { # grootte in kilobytes } elseif( filesize( $path . "/" . $f_arr[$i] ) >= 1048576 ) { # grootte in megabytes } else { # grootte in bytes print " " . filesize( $path . "/" . $f_arr[$i] ) . " bytes<br />"; } ?>
|