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:

echo "<h1>MSDS Docs</h1>";

$path = "/v2/docs/";

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


What am I missing here?  To what extent will I be able to format the output, if I ever get there...........
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Make sure your path is correct could be ../v2/docs/
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:


and nothing shows on the page.
pmagonyAuthor Commented:

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?
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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

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.
I told you to make sure the path was correct ;-)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pmagonyAuthor Commented:
Just like my wife :^P
Oh, you got one like that too, thanks for the points and the grade.
pmagonyAuthor Commented:
Haha... no problem... thanks for the assist.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.