I am trying to make a code to navigate through a directory in PHP
function navigate($path){
$directorio = $_SERVER['DOCUMENT_ROOT'] . '/' . $path;
$scan = scandir($directorio);
return $scan;
}
session_start();
$dir = $_SERVER['DOCUMENT_ROOT'] . '/';
if(ISSET($_POST['datei'])){
echo $_POST['datei'];
$_SESSION['actualdir'] = $dir . $_POST['datei'];
$scanner = navigate($_SESSION['actualdir']);
}
if(!ISSET($_POST['datei'])){
$scanner = scandir($dir);
}
The $scan and $scanner variables are arrays that go to a dropdown to choose the next folder. However my code only works twice.
Example:
We start in folder.
Then the dropdown shows nextfolder
We are now in folder/nextfolder.
We choose anyfolder again.
The program goes to folder/anyfolder instead of folder/nextfolder/anyfolder.
Any ideas? I guess I should keep saving the current directory somehow. Yet I have no idea how to do it.