troubleshooting Question

How to let opendir read a directory in the Unix filesystem?

Avatar of mattias_swe
mattias_swe asked on
PHPApache Web ServerSystem Programming
3 Comments1 Solution407 ViewsLast Modified:
I am creating an web app that needs to read a directory and print what's in it.
That is not to hard in php, but my knowledge in unix permissions fails me.
Here is my code so far:
$link = "documents";
if(is_link($link)) {
      $dir = readlink($link);

      if($dh = opendir($dir)) {
            while(($file = readdir($dh)) !== false) {
                  echo "filename: $file -- filetype ".filetype($dir.$file)."\n";

As you can see I am pointing to a folder via a sym link, I thought I could fool the system by doing that. ;)
I can't do opendir directly to the folder so I tried the sym link way instead.

The error I get is:
Warning: opendir(/Volumes/MirrorDrive/SharedItems/Documents/) [function.opendir]: failed to open dir: Permission denied in /Library/WebServer/Documents/documentserver/readdir.php on line 8

I guess this is a such noob question that most of you laugh at it.
But please give me a few minutes to answer my question. :)

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros