• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1129
  • Last Modified:

Display Folder Contents on Page, PHP opendir

I'm trying to display a directory of PDF files on my website.  The following script is yielding a blank page:

<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
echo "<h1>MSDS Docs</h1>";

$path = "/v2/docs/";

$dh = opendir($path);
while (($file = readdir($dh)) !== false) {
    echo "<a href='$path/$file'>$file</a><br />";
}
closedir($dh);

?>

What am I missing here?  To what extent will I be able to format the output, if I ever get there...........
0
pmagony
Asked:
pmagony
  • 6
  • 3
1 Solution
 
gamebitsCommented:
Make sure your path is correct could be ../v2/docs/
0
 
pmagonyAuthor Commented:
The file that contains this script, is at the root of the web directory (httpdocs).  The subfolder /docs/ contains the PDF's I am referring too...  

So I've tried:

/docs/
/docs
docs

and nothing shows on the page.
0
 
pmagonyAuthor Commented:
Hi,

Ok, well atleast now I can get the page to tell me that it's unable to open the path I am specifying.  I've pointed all the way from server root to the main directory itself, and it produces the same error for all paths.

Do you think this is a permission error?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
pmagonyAuthor Commented:
This would  help:

<?

//define the path as relative
$path = "manuals";

//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");

echo "Directory Listing of $path<br/>";

//running the while loop
while ($file = readdir($dir_handle))
{
   if($file!="." && $file!="..")
      echo "<a href='$file'>$file</a><br/>";
}

//closing the directory
closedir($dir_handle);

?>
0
 
pmagonyAuthor Commented:
I got it... it's working!   For the others who read this, the path has to be the full server path.  Relative paths will not work.
0
 
gamebitsCommented:
I told you to make sure the path was correct ;-)
0
 
pmagonyAuthor Commented:
Just like my wife :^P
0
 
gamebitsCommented:
Oh, you got one like that too, thanks for the points and the grade.
0
 
pmagonyAuthor Commented:
Haha... no problem... thanks for the assist.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now