Page 1 of 1

create directory links like "DevNetwork Forums Forum In

Posted: Fri Dec 14, 2007 10:04 am
by farkewie
Hi i have a page that browses through all the directorys on my site it works right from d:/ through to my deepest directory, it is only run on a local network,

the way it knows which directory to display and link to is the url GET variable "dir"

ie:

$dir = "$_GET['dir'];

which may be "/dir1/dir2/dir3/dir4"

i amd trying to create a link set at the top of the page so i can go back to anyone of the upper directorys

it will look like this

"home --> dir1 --> dir2 --> dir3"

the link will be some this like mypage.php?dir=/dir1
so the above example would be

mypage.php --> mypage.php?dir=/dir1 --> mypage.php?dir=/dir1/dir2 --> mypage.php?dir=/dir1/dir2/dir3

my code is displaying 2 of every link and also i cant get it to inclue all the previous directorys like this one "mypage.php?dir=/dir1/dir2"

Code: Select all

<?php

 $links = explode( "/", $_GET['dir'], 2 );
 echo $_GET['dir'] . "<br/><br/><br/>"; //Testing
 echo $links . "<br/><br/><br/>";   //Testing
 if ( ($_GET['dir']) != "" and is_array($links) )
 {
     for ( $i = 1; $i <= sizeof($links); $i++ )
     {
         if ( $links[$i] != "" )
         {
             foreach ( $links as $link )
             {
                 echo " -> <a href=\"{$_SERVER[PHP_SELF]}?inc=z&dir={$link}\">$link</a> ->";
             }


         }
     }

 }
?>

Posted: Fri Dec 14, 2007 11:35 am
by vigge89
This snippet of code is what I commonly resort to when showing breadcrumb paths:

Code: Select all

<?php
// Quick and dirty part, don't copy this directly (just illustrational)
$path = $_GET['dir'];
$self = $_SERVER['SCRIPT_NAME'];

// Explode path into breadcrumbs
$breadcrumbArray = explode('/', trim($path, '/'));
if (!is_array($breadcrumbArray) || strlen($breadcrumbArray[0]) < 1)
	$breadcrumbs = array();
else foreach ($breadcrumbArray as $key => $bc) {
	$breadcrumbs[$key] = array($bc, '');
	for ($i = 0; $i <= $key; ++$i)
		$breadcrumbs[$key][1] .= '/'.$breadcrumbArray[$i];
	$breadcrumbs[$key][1] .= '/';
}
?>

...

<h1><a href="<?php echo $self ?>">Root</a><?php foreach ($breadcrumbs as $bc): ?> › <a href="<?php echo htmlentities($self.$bc[1]) ?>"><?php echo htmlentities($bc[0]) ?></a><?php endforeach; ?></h1>

Posted: Fri Dec 14, 2007 4:56 pm
by farkewie
Thank you so much