msidnam
asked on
Looking for PHP code to view folders and files
I have an Ubuntu box running Apache2 and PHP5. I've created a web site on the Ubuntu box. I'm looking for PHP code that when i go to that web site will list for me the folders and files (that i can click and view) inside a share that will be mounted on the Ubuntu box.
This will list all files and foders in a specified directory:
<?php
// declare the folder
$ourDir = "/home/public_html/folderName";
// prepare to read directory contents
$ourDirList = @opendir($ourDir);
// loop through the items
while ($ourItem = readdir($ourDirList))
{
// check if it is a directory
if (is_dir($ourItem))
{
echo "directory: $ourItem <br />";
}
// check to see if it is a file
if (is_file($ourItem))
{
echo "file: $ourItem <br />";
}
}
closedir($ourDirList);
?>
ASKER
Is their a way to be able to click throght the directories and open files?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank you. When i did a search for php file manager it brought me to a site that had some code and learning areas.
http://www.php.net/manual/en/function.readdir.php