Link to home
Create AccountLog in
Avatar of msidnam
msidnamFlag for United States of America

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.
Avatar of hernst42
hernst42
Flag of Germany image

Avatar of rstewar
rstewar

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);
 
?>

Open in new window

Avatar of msidnam

ASKER

Is their a way to be able to click throght the directories and open files?
ASKER CERTIFIED SOLUTION
Avatar of hernst42
hernst42
Flag of Germany image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of msidnam

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.