对于文件管理系统我想从网址创建php中的一些面包屑。 每个用户的根目录在url:
中如下所示example.com/sfm?dir=uploads/sfm/root
在rootdir中有一个名为folder1
的文件夹
点击folder1时,网址为:
example.com/sfm?dir=uploads/sfm/root/folder1
在folder1中有一个名为folder2
的文件夹
点击该文件夹时,网址将变为:
example.com/sfm?dir=uploads/sfm/root/folder1/folder2
依旧...... 如何根据网址制作一些带有锚点到文件夹的面包屑?
答案 0 :(得分:1)
如果我理解正确,您要做的就是接受$_GET['dir']
的竞争并按/
拆分,然后提供每个竞争的链接。
我将如何做到这一点:
$crumbs=explode('/',$_GET['dir']); // this splits the sections of $_GET['dir'] separated by / into an array of values
$url_pre=''; // we'll use this to keep track of the crumbs we've sifted through already
// foreach cycles through each element in an array
// $crumbs is the array, and $crumb is the current listing in the array we're looking at
foreach($crumbs as $crumb){
$url_pre.=.$crumb;
echo '<a href="?dir='.$url_pre.'">'.$crumb.'</a>';
$url_pre.='/'; // add this after you echo the link, so that dir doesn't start with a /
}