Page 1 of 1

Directory viewer

Posted: Thu Oct 16, 2003 4:12 am
by Deimos
Here's a script to show all your current files within the directory you place this file in, you can also create your own style sheet for this, so you can adjust the design easily.



[php]

<?php

$scriptLocation = ""; // Point this to a refernce to a style sheet (Embeeded CSS will be ingnorned)



$scriptCSS = "

<style>

BODY {

margin: 1em;

font-family: Arial;

line-height: 1.1;

background: #3f3f3f;

color: #999999;

}



A:link { color: #cccccc;} /* unvisited link */

A:visited { color: #cccccc;} /* visited links */

A:active { color: #555555; background: #999999;} /* active links */

A:hover { color: #cccccc; background: #555555;}



TD { background: #555555 }



INPUT.SUBMIT { background: #999999; }

</style>

";

/*

** CSS (Style Sheet) Definition Finished

*/





/*

** Display Disk Space Usagae and Free

*/

$scriptStats = "1"; // 1 for Yes - 0 for No









/*

*********************** DO NOT MODIFY BELOW THIS LINE ***********************

*/

function dirHeader() {

$content = "<table width=100% nowrap>";

return $content;

}



function dirTable() {

$content = "<tr><td><b><font size=-1>Type</font></b></td><td width=50%><b><font size=-1>Name</font></b></td><td><b><font size=-1>Size</font></b></td><td><b><font size=-1>Modified</font></b></td></tr>";

return $content;

}





function dirFooter() {

$content = "</table>";

return $content;

}



function fType($file) {

$varFileType = filetype($file);

if($varFileType != "dir") {

$curdir = getcwd();

$pInfo = pathinfo("$curdir/$file");

$varFileType = $pInfo["extension"];

}

return $varFileType;

}





function fileView($file) {

$varType = strtolower(fType($file));

$varJSSettings = "width=300,height=300,resizable=1,scrollbars=1,menubar=0,status=0,titlebar=0,toolbar=0,hotkeys=0,locationbar=0";

$txtArray[] = "txt";

$txtArray[] = "nfo";

$txtArray[] = "diz";

$txtArray[] = "now";

$txtArray[] = "bmp";

$txtArray[] = "jpg";

$txtArray[] = "gif";

$txtArray[] = "doc";

$txtArray[] = "1st";

$txtArray[] = "now";

$txtArray[] = "me";

if(in_array($varType, $txtArray)) {

$content = " - (<a href=\"#\" onClick=\"window.open('$file', 'viewer','$varJSSettings');\">view</a>)";

}

return $content;

}

function display_size($file_size){

if($file_size >= 1073741824) {

$file_size = round($file_size / 1073741824 * 100) / 100 . "g";

} elseif($file_size >= 1048576) {

$file_size = round($file_size / 1048576 * 100) / 100 . "m";

} elseif($file_size >= 1024) {

$file_size = round($file_size / 1024 * 100) / 100 . "k";

} else {

$file_size = $file_size . "b";

}

return $file_size;

}



function dirGather() {

$handle=opendir(".");

$content = "";

//while (false!=($file = readdir($handle))) {

while ($file = readdir($handle)) {

if(($file != "index.txt") && ($file != "index.php")) {

$filetype = fType($file);

if($filetype == "dir") {

$dirtext[] = "$file";

} else {

$context[] = "$file";

}

}

}

if($dirtext) {

sort($dirtext);

for($i=0; $i<count($dirtext); $i++) {

$file = $dirtext[$i];

$lastchanged = filectime($file);

$changeddate = date("d-m-Y H:i:s", $lastchanged);

$filesize = display_size(filesize($file));

$filetype = fType($file);

$viewfile = fileView($file);

$content .= "<tr><td><font size=-1>$filetype</font></td>";

$content .= "<td><font size=-1><a href=\"$file\">$file</a> $viewfile</font></td>";

$content .= "<td><font size=-1>$filesize</font></td>";

$content .= "<td><font size=-1>$changeddate</font></td></tr>";

}

}

if($context) {

sort($context);

for($i=0; $i<count($context); $i++) {

$file = $context[$i];

$lastchanged = filectime($file);

$changeddate = date("d-m-Y H:i:s", $lastchanged);

$filesize = display_size(filesize($file));

$filetype = fType($file);

$viewfile = fileView($file);

$content .= "<tr><td><font size=-1>$filetype</font></td>";

$content .= "<td><font size=-1><a href=\"$file\">$file</a> $viewfile</font></td>";

$content .= "<td><font size=-1>$filesize</font></td>";

$content .= "<td><font size=-1>$changeddate</font></td></tr>";

}

}

return $content;

}



function diskStats($scriptStats) {

if($scriptStats) {

// $diskTotal = display_size(disk_total_space("/"));

$diskFree = display_size(diskfreespace("/"));

$content = "<table width=100%>";

$content .= "<tr><td width=150><b><font size=-1>Free Disk Space:</font></b></td><td><font size=-1>$diskFree</font></td></tr>";

// $content .= "<tr><td width=150><b><font size=-1>Total Disk Space:</font></b></td><td><font size=-1>$diskFree</font></td></tr>";

$content .= "</table>";

print($content);

}

}

?>

<html>

<head>



<? if($scriptLocation == "") {

print($scriptCSS);

} else {

print("<LINK REL=stylesheet HREF=\"$scriptLocation\" TYPE=\"text/css\">");

} ?>

</head>

<body>

<?



diskStats($scriptStats);

print(dirHeader());

print(dirTable());

print(dirGather());

print(dirTable());

print(dirFooter());

diskStats($scriptStats);

?>[/php]