Page 1 of 1

Showing the path of a folder...

Posted: Wed Jan 14, 2004 6:45 pm
by Mr. Tech
I have a script that shows the files and folders in the $folder directory.

In the address bar, you would have something like this:

index.php?folder=folder1/folder2/folder3

I am wanting to display a link to each of those folders on the page:

Code: Select all

<?php
$show_folders = explode("/", $folder);
for($i = 0; $i < count($show_folders); $i++) {
$where .= " / <a href="{$PHP_SELF}?folder={$show_folders[$i]}">".$show_folders[$i]."</a>";
}
?>
But the problem with the code above is that it doesn't show the complete path... It ends up looking like this:

/ <a href="index.php?folder=folder1">folder1</a> / <a href="index.php?folder=folder2">folder2</a> / <a href="index.php?folder=folder3">folder3</a>

And I want it to look like this:

/ <a href="index.php?folder=folder1">folder1</a> / <a href="index.php?folder=folder1/folder2">folder2</a> / <a href="index.php?folder=folder1/folder2/folder3">folder1/folder2/folder3</a>

Is there anyway I can do that?

Posted: Wed Jan 14, 2004 6:48 pm
by Gen-ik
Try this.

Code: Select all

<?php 

$show_folders = explode("/", $folder); 

$new_path = "";

for($i = 0; $i < count($show_folders); $i++)
{
    $new_path.= $show_folders[$i];
    $where .= '<a href="{$PHP_SELF}?folder={$new_path}">{$new_path}</a>'; 
} 
?>