I am looking to build a directory browser in PHP. I have just started my code, but need someone to help me complete or modify it.
$dir = dirname(__FILE__); //pat
While you develop this, its important to recognize that you are dealing with two different directory paths. One path is URL based, the other is Document based. The path / would take you to the root of your site where C:\some path\www\ would also take you there. Both of these reference the same location, using different means.
With that said, you're going to have to use URL based paths the navigate your interface (unless you don't care about exposing your document path - SECURITY RISK), but the code needs to take what you've clicked and convert it to Document based paths. Here are some PHP functions which might help.
__FILE__ - gives you the document path to the current PHP file
__DIR__ or dirname(__FILE__) - gives you the document path to the folder the current file is at
getcwd() - gets the current working directory
Also, instead of having the link go to the file path, have it post the file path and reload the page based on the posted data.
<form name='myform' method='post'>
<a href='folderA' onclick="document.myform.path.value=this.getAttribute('href'); document.myform.submit(); return false;">Folder A</a>
<a href='folderB' onclick="document.myform.path.value=this.getAttribute('href'); document.myform.submit(); return false;">Folder B</a>
<input type='hidden' name='path' value='' />
</form>