Solved

Display Folder Contents on Page, PHP opendir

Posted on 2007-03-29
9
1,115 Views
Last Modified: 2008-02-07
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
Comment
Question by:pmagony
  • 6
  • 3
9 Comments
 
LVL 28

Expert Comment

by:gamebits
Comment Utility
Make sure your path is correct could be ../v2/docs/
0
 
LVL 9

Author Comment

by:pmagony
Comment Utility
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
 
LVL 9

Author Comment

by:pmagony
Comment Utility
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
 
LVL 9

Author Comment

by:pmagony
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 9

Author Comment

by:pmagony
Comment Utility
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
 
LVL 28

Accepted Solution

by:
gamebits earned 500 total points
Comment Utility
I told you to make sure the path was correct ;-)
0
 
LVL 9

Author Comment

by:pmagony
Comment Utility
Just like my wife :^P
0
 
LVL 28

Expert Comment

by:gamebits
Comment Utility
Oh, you got one like that too, thanks for the points and the grade.
0
 
LVL 9

Author Comment

by:pmagony
Comment Utility
Haha... no problem... thanks for the assist.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now