Miscellaneous
|
|
|
|
<?
// preform.php
// by philip_gleghorn@yahoo.co.uk
//
// scan a directory specified in the $REQUEST_URI
// show all directories as self-named hyperlinks
// show all MSIE style *.url files as hyperlinks named by url destination
// show all other files as self-named hyperlinks
//
// isort function by richard.heyes@heyes-computing.net
// obtained from www.zend.com
function isort($a,$b){
if(ord(substr(strtolower($a),0,1)) == ord(substr(strtolower($b),0,1))) return 0;
return (ord(substr(strtolower($a),0,1)) < ord(substr(strtolower($b),0,1))) ? -1 : 1;
}
$request = urldecode($REQUEST_URI);
// we have to chdir else filetype() and filesize() (and friends) will fail
//
chdir("/mnt$request");
echo "<table width="100%"><tr width="100%"><td>Viewing /mnt" . $request . "</td><td align="right"><a href="/preform.phps">preform.php</a></td></tr></table>";
$handle=opendir("/mnt${request}");
$dirs_array = array();
$urls_array = array();
$other_array = array();
while ($file = readdir($handle)) {
if (filetype($file) == "dir") {
$dirs_array[] = $file;
} else {
$pos = strpos ($file, ".url");
if ($pos == 0) {
$others_array[] = $file;
} else {
$urls_array[] = $file;
}
}
}
closedir($handle);
if (count($dirs_array) > 0) {
usort($dirs_array, 'isort');
reset($dirs_array);
echo "<table border=0>";
foreach($dirs_array as $myval) {
$mylink="/";
if (($myval == "..") && (($request=="/gleghorn/favs/") || ($request=="/gleghorn/khome/"))) {
$mylink="/";
} else {
$mylink = $myval;
}
echo "<tr bgcolor="#440000"><td><a href="$mylink">$myval</a></td></tr>";
}
echo "</table><p>";
}
if (count($urls_array) > 0) {
usort($urls_array, 'isort');
reset($urls_array);
echo "<table border=0>";
foreach($urls_array as $myval) {
$farr = file("/mnt$request$myval");
$furl = $farr[1];
$ftok = strtok ($furl, '=');
$ftok = strtok ('=');
$ftok = substr($ftok, 0, strlen($ftok)-2);
echo "<tr bgcolor="#004400"><td>" . substr($myval, 0, strlen($myval)-4) . "</td><td><a href="$ftok">$ftok</a></td></tr>";
}
echo "</table><p>";
}
if (count($others_array) > 0) {
usort($others_array, 'isort');
reset($others_array);
echo "<table border=0>";
foreach($others_array as $myval) {
$mylink="/";
if (($myval == "..") && (($request=="/gleghorn/favs/") || ($request=="/gleghorn/khome/"))) {
$mylink="/";
} else {
$mylink = $myval;
}
echo "<tr bgcolor="#000044"><td><a href="$myval">$myval</a></td><td>" . filesize($myval) . "</td><td>bytes</td></tr>";
}
echo "</table><br>";
}
echo "n<!-- automatically generated by preform.php, Phil Gleghorn <philip_gleghorn@yahoo.co.uk> -->";
?>
|
|
|
Usage Example
|
|
|
Rate This Script
|
|
|
|