[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Display Folder Contents on Page, PHP opendir

Posted on 2007-03-29
9
Medium Priority
?
1,128 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 28

Expert Comment

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

Author Comment

by:pmagony
ID: 18816147
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
ID: 18816570
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 9

Author Comment

by:pmagony
ID: 18816573
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
 
LVL 9

Author Comment

by:pmagony
ID: 18816636
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 2000 total points
ID: 18816769
I told you to make sure the path was correct ;-)
0
 
LVL 9

Author Comment

by:pmagony
ID: 18816972
Just like my wife :^P
0
 
LVL 28

Expert Comment

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

Author Comment

by:pmagony
ID: 18817107
Haha... no problem... thanks for the assist.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

649 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