php: Directory viewer
Posted: Thu Oct 16, 2003 4:13 am
Here's a script for viewing the files and dirs in the directory this file is placed in.. I couldn't post it at one time, so I devided it in 2 halfs. You should paste the 2 parts together to make it work. You can add a style sheet to adjust the design.
[php]<?php
$scriptLocation = ""; // Point this to a refernce to a style sheet (Embeeded CSS will be ingnorned)
$scriptCSS = "
";
/*
** 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;
}
?>//Forget this line it's not needed when you past part 2 here
[/php]
[php]<?php
$scriptLocation = ""; // Point this to a refernce to a style sheet (Embeeded CSS will be ingnorned)
$scriptCSS = "
";
/*
** 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;
}
?>//Forget this line it's not needed when you past part 2 here
[/php]