Request for Comments on two column Micro File Manager from n00b

Request for Comments on two column Micro File Manager from n00b

am 22.12.2007 02:15:28 von Tiz

code review request

A couple of days ago, I was dismayed to find my ~/public_html directory
choked with junk files. I wanted a micro file manager to be able to
parse the files and directories quickly and it seems like php is the
answer.

I found a public domain script on www.phptoys.com called
microFileManager.php that I based the following code. The original code
used tables. The code below uses a style sheet and presents the
directory listing in column 1 and the selected file content in column 2
in a basic menu/content 2 column format.

Sample style sheet provided.

I'm new to php and would appreciate feedback on this script. Layout,
function calls, error handling - whatever. Perhaps there are php classes
or functions that can do this better.

The micro file manager requirements are...

o create a well written php script

o not to exceed 100 lines of code

o wrapping at column 80 - personal preference - posting to
newsgroup would make this requirement difficult at best -
so perhaps this should read - readable code.

o directory listings displayed on left column

o selecting item in listing displays item in right column

o two files only, the script and the stylesheet. No extra
gifs, functions, features.

o no tables

CODE:

function showHeader($path) {
print "

";
}
function showMenu($path) {

if ($handle = opendir($path))
{
print "";
closedir($handle);
}
}

function showContent($path, $fn){
print "
";
print "

$fn

";
$imageext = array(jpg, jpeg, JPEG, JPG, gif, png);
$textext = array(txt, cfg, sql, css, plugin);
$path_parts = pathinfo($fn);
if (in_array($path_parts['extension'], $imageext, true)) {
echo '';
} elseif (in_array($path_parts['extension'], $textext, true)) {
echo '
';
include("$path/$fn");
echo '
';
} else {
include("$path/$fn");
}
print "
";
}

if (isset($_POST['submitBtn'])){
$actpath = isset($_POST['path']) ? $_POST['path'] : '.';
} else {
$actpath = isset($_GET['path']) ? $_GET['path'] : '.';
}

if (isset ($_GET['file']) )
{
$filename = $_GET['file'];
}

showHeader($actpath);

showMenu($actpath);

if (isset($filename)){
showContent($actpath, $filename);
}

?>

CODE:
body {
margin:0px;
padding:0px;
font-family:verdana, arial, helvetica, sans-serif;
color:#333;
background-color:white;
}
h1 {
margin:1px 0px 15px 0px;
padding:0px;
font-size:18px;
line-height:28px;
font-weight:900;
color:#ccc;
}
p {
font:11px verdana, arial, helvetica, sans-serif;
margin: -10px 0px 0px 0px;
}
#Menu h2
{
color:#99A575;
font-size:13px;
text-decoration:none;
font-weight:600;
font-family:verdana, arial, helvetica, sans-serif;
}
a {
color:#99A575;
font-size:11px;
text-decoration:none;
font-family:verdana, arial, helvetica, sans-serif;
}
a:link {color:#99A579;}
a:visited {color:#93604f;}
a:hover {background-color:#eeeeee;}
#Header {
margin:20px 0px 10px 210px; /* space from top, width, height,
inside margin */
padding:17px 0px 0px 10px;
border-style:solid;
border-color:black;
border-width:1px 1px; /* top and bottom borders, left and right
borders */
line-height:11px;
background-color:#eeeeee;
voice-family: "\"}\"";
voice-family:inherit;
}
body>#Header {height:14px;}

#Content {
margin:0px 50px 50px 220px;
padding:10px;
font:11px/20px verdana, arial, helvetica, sans-serif;
}

#Menu {
position:absolute;
top:20px;
left:20px;
padding:10px;
background-color:#EFE9C4; /* Menu background */
border:1px;
dashed #999;
line-height:17px;
voice-family: "\"}\"";
voice-family:inherit;
border-style:solid;
}
body>#Menu {width:170px;} /* Menu width */

CODE: header it insert style sheet.

"DTD/xhtml1-transitional.dtd">


File Browser



replace this line with php code