Jump to content

Directory Navigation (With Upper Limit)


GITs

Recommended Posts

Ok, I'm in need of a little bit of help with a piece of coding I'm doing. It is supposed to list the contents of a directory (easy enough) and allow the user to look at what is in the sub-directories aswell (also quite easy)

 

The problem comes when I try to limit the user from going above the main directory...

 

Here is what I have so far (please excuse the useless echo outputs, I'm using them for debugging purposes)

 

<?php

$up = 0;
$base = "D:/AnimeUploaded/";
$pathworking = $_GET[path];

echo $pathworking."1<p/>";

if(strpos("/..",$pathworking)){
  $pathworking = str_replace("/..","",$pathworking);
   $up = 1;
}

echo $pathworking."2<p/>".$up."up<p/>";
if($up == 1){
   if($pathworking != ""){
      echo "added<p/>";
      $pathworking = $pathworking."/..";
   }
}
echo $pathworking."3<p/>";

$dir = opendir($base.$pathworking) or die("Sorry, Unable to access that folder, please contact the administrator at [email protected]");

echo "Directory Listing of $base.$pathworking<br/>";

//running the while loop
while ($file = readdir($dir)) 
{
if(strpos($file, '.')){
   echo "<a href='http://www.l9ianime.com/anime/".$pathworking."/".$file."'>".$file."</a><br/>";
}
else{
echo "<a href='http://www.l9ianime.com/index.php?q=node/39&path=".$pathworking."/".$file."'>/".$file."</a><br/>";
}
}

//closing the directory
closedir($dir);

?>

Link to comment
https://forums.phpfreaks.com/topic/49353-directory-navigation-with-upper-limit/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.