Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Display Folders

Status
Not open for further replies.

aspphp

IS-IT--Management
Dec 15, 2009
12
YE
I put in similar request before, for some reason I could not get it to work. I am requesting it again, for code or examples.

First I want to display 'only folders'like,
-- /inetpub/-- /inetpub/
once I click on folderOne, I want to display 'subfolder' if any, and I want to display only 'pdf' files with 'href' link. So on with folderTwo.

Bottom line, 'disply folders', 'subfolders', and only 'pdf' files -- using PHP or Javascript.

Thank you in advance.
 
Look at opendir() and readdir() . Some good examples in their respective entries in the php.net online manual, just click the function names to go there.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Sorry to write this, I tried what you said, other
sources. But for some reason I could not figured
out. If will be big help if you can provide
me the sample code

Thanks in advance.
 
Well what have you tried?

Here's a simple script that will list the contents in your website's root folder.
Click on a folder and it will list the contents of that folder.

You should be able to go from there.

Code:
<?PHP

if(isset($_GET['dir'])){
$dir=$_GET['dir'];
}
else{
$dir='.';

}

if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
echo "<a href='dispdir.php?dir=". $file . "'>" . $file . "</a><br>";
      
        }
        closedir($dh);
    }
}
else{
echo "$dir is not a folder";
}
?>





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top