Im really new with php and kind of just teachin myself how. I cant figure out how to fix this... been toiling all morning. Everything seems to work fine except for one thing. When you are navigating through the directories it works but when you click on a file it opens the file but the menu resets back to the root. I need it to stay in the directory you are in. I know why it does this... kinda, if you look in the address bar it passes the "name" variable but it loses "path" somewhere along the way. I think i need to pass both variables at the same time????? Or rework some other bit of it... Please help me fix up this mess. Any other sugestions on how to tidy up or fix this script would be great too. Thanks for any help in advance.
by the way, ignore the static links on the page. not linked properly yet.
Example page on my server :
http://grewal.mine.nu/bruno/
The php:
<?php
//dynamic menu on the side
# Do we have a path? if not, it's the current directory
$path = $_GET["path"];
if( !isset( $path ) || $path == "" ) {
$path = "./";
}
# Initialise list arrays, directories and files separately and array counters for them
$d_arr = array(); $d = 0;
$f_arr = array(); $f = 0;
# Open possibly available directory
if( is_dir( $path ) ) {
if( $handle = opendir( $path ) ) {
while( false !== ( $file = readdir( $handle ) ) ) {
# Make sure we don't push parental directories or dotfiles (unix) into the arrays
if( $file != "." && $file != ".." && $file != "php" && $file != "index.php" && $file != "load.php" && $file != "includes" && $file != "paragraph.php" ) {
if( is_dir( $path . "/" . $file ) )
# Create array for directories
$d_arr[$d++] = $file;
else
# Create array for files
$f_arr[$f++] = $file;
}}}}
# Wrap things up if we're in a directory
if( is_dir( $handle ) ) closedir( $handle );
# Sort and reset the arrays
sort( $d_arr ); reset( $d_arr );
sort( $f_arr ); reset( $f_arr );
echo "<b><u>Index of: </u></b><br>";
print "<i>" . $path . "</i><br><br>";
# Print a go back link
$d_prev = substr( $path, 0, ( strrpos( dirname( $path . "/." ), "/" ) ) );
print "<a href=\"?path=" . $d_prev . "\"> Go Back </a><br><br />\n";
# Print the directory list
for( $i=0; $i < count( $d_arr ); $i++ ) {
# Print with query string
print "<a href=\"?path=" . $path . "/" . $d_arr[$i] . "\">" . $d_arr[$i] . "</a><br />\n";
}
# Print file list
for( $i=0; $i < count( $f_arr ); $i++ ) {
# Only print path and filename
print "<a href=\"?name=" . $path . "/" . $f_arr[$i] . "\" > " . $f_arr[$i] . "</a><br />\n";
}
?>
<?
// this part loads the page or the pic
$file = $_GET["name"];
if( !isset( $file ) || $file == "" ) {
$file = "includes/page.php";
}
if ( stristr($file, ".jpg") or stristr($file, ".gif") or stristr($file, ".bmp")) {
echo "<img border='0' src='$file' width='50%' height='50%'>" ;
}
else
{
$lines = file($file);
foreach($lines as $val)
{
echo "$val<br>\n";
}}
?>