PDA

View Full Version : link doesnt work right, Cant figure it out :(


bruno
08-30-2005, 05:54 PM
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 page would be great too. Thank[s 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";
}}
?>

01482
08-31-2005, 04:24 AM
It would be better in PHP BBCode tags...



<?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";
}}
?>

Vege
08-31-2005, 05:35 AM
If you put the tittlebar like so, it works:

http://grewal.mine.nu/bruno/?path=.//Poetry/Bruno%20Grewal/Poems%20from%202000/&name=.//Poetry/Bruno%20Grewal/Poems%20from%202000/[3]%20Always%20too%20late
But thats so messy that it brokes my eyes :moonie:
Maby you can sort a cleaner solution

bruno
08-31-2005, 01:17 PM
Sorry 01482, i fixed it. and Vege, i know it works if you manualy type it in. I just dontk now how to fix the link. i dont really care if address bar is messy just as long as it works.

Vege
08-31-2005, 02:58 PM
# Only print path and filename
print "<a href=\"?name=" . $path . "/" . $f_arr[$i] . "&amp;path=" . $path . "/" . $d_arr[$i] . "\" > " . $f_arr[$i] . "</a><br />\n";

This adds the both strings on the link, paths are seperated with the & ( &amp; ) sign
So now the user shoud get where he wants to?

bruno
08-31-2005, 04:22 PM
Thank you Vege that fixed that issue.