Hi there,
I searched for a good file manager ( used for an intranet ) now for 3 days, but haven't really found anything applicable. there are a few, but I couldn't get them to work properly.
I now used a code from the php4 wrox book. It's almost working fine, the directories and files are listed and are also turned into links, but once I click a directory link for example, it doesn't do anything. It reloads ( $PHP_SELF ) but for some reason it doesn't take the new value for the new dir variable. The generated link looks like this :
http://localhost/wrox/php_dir/navigator.php?dir=./test1
But instead of switching to the tes1 dir, it stays in the current dir, which is "."
<?php
//navigator.php
//include "common.inc";
$default_dir = ".";
$text_file_array = array( "txt", "htm", "html", "php", "inc", "dat" );
$image_file_array = array("gif", "jpeg", "jpg", "png");
function html_header() {
?>
<HEAD><TITLE>Welcome to Web Text Editor</TITLE></HEAD>
<BODY>
<?php
}
function html_footer() {
?>
</BODY>
<?php
}
function error_message($msg) {
html_header();
echo "<SCRIPT>alert(\"$msg\"); history.go(-1)</SCRIPT>";
html_footer();
exit;
}
function display() {
global $filename, $dir, $text_file_array, $image_file_array;
$extension = array_pop(explode(".", $filename));
if(in_array($extension, $text_file_array)) {
readfile("$dir/$filename");
}
else if(in_array($extension, $image_file_array)) {
echo "<IMG SRC=\"$dir/$filename\">";
}
else echo "Cannot be displayed. $dir/$filename has not been
recognised as a text file, nor as a valid image file. ";
}
function dir_page() {
global $dir, $default_dir, $PHP_SELF, $default_filename;
if($dir == '') {
$dir = $default_dir;
}
$dp = opendir($dir);
?>
<TABLE BORDER="0" WIDTH="100%" CELLSPACING="0" CELLPADDING="0">
<?php
while($file = readdir($dp)) $filenames[] = $file;
sort($filenames);
for($i = 0; $i < count($filenames); $i++)
{
$file = $filenames[$i];
if($dir == $default_dir && ($file == "." || $file == ".."))
continue;
if(is_dir("$dir/$file") && $file == ".")
continue;
if(is_dir("$dir/$file")) {
if($file == ".."){
$current_dir = basename($dir);
$parent_dir = ereg_replace("/$current_dir$","",$dir);
echo "<TR><TD WIDTH=\"100%\" NOWRAP>
<A HREF=\"$PHP_SELF?dir=$parent_dir\">$file/
</A></TD></TR>\n";
}
else echo "<TR><TD WIDTH=\"100%\" NOWRAP>
<A HREF=\"$PHP_SELF?dir=$dir/$file\">
$file/</A></TD></TR>\n";
}
else echo "<TR><TD WIDTH=\"100%\" NOWRAP>
<A HREF=\"$PHP_SELF?action=display&dir=$dir&filename=$file\"
TARGET=\"_blank\">$file</A></TD></TR>\n";
}
echo "<h1>" . $dir . "</h1>";
closedir($dp);
?>
</TABLE>
<?php
}
if(empty($dir) || !ereg($default_dir, $dir)) {
$dir = $default_dir;
}
switch ($action) {
case "display":
display();
break;
default:
html_header();
dir_page();
html_footer();
break;
}
?>
What am I doing wrong ? I tried webexplorer2, worked fine, but had the same problem as above. Couldn't browse subdirectories.
Any help appreciated ---------- cheers .
ad