Forum Moderators: coopster
how do you make a script link back to
site.com/some/random/ammount/of/
without being thrown off by (note no trailing slash)
site.com/some/random/ammount/of/folders
my loop looks like this
$dir="dir/";
$d=dir($dir);
while($f=$d->read()) {
if($f == "..") {
//change link
} else {
//other stuff
}
}
$d->close();
<?
if (!$dir) $dir = "dir/";
$d = dir($dir);
while($entry = $d->read()) {
if($entry!= ".") {
if(is_dir($dir.$entry)){
$r[] = "<a href=\"".$PHP_SELF."?dir=".$dir."/".$entry."/\">".$entry."</a>";
}else{
$f[] = "<a href=\"".$dir.$entry."\">".$entry."</a>";
}
}
}
natcasesort($r);
natcasesort($f);
$html = "<h2>folders</h2>".implode("<br>",$r)."<hr><h2>files</h2>".implode("<br>",$f);
echo $html;
?>
so if you click ../ your url ends up looking like this
[site.com...]
when it could be simplified to
[site.com...]
However if there are many many folders then this is probably not practicle. There are many ways to do this kind of thing, but without much of your code it's hard to advise.
regex may well prove to be the best way.
$path = explode("/",$URL);
$pathcopy = array();
foreach($path as $k=>$v){
if ($v==".."){
array_pop($pathcopy);
}else{
array_push($pathcopy,$v);
}
}
$URL=implode("/",$pathcopy);