Showing the path of a folder...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Showing the path of a folder...

Post 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?
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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>'; 
} 
?>
Post Reply