Member_2_5175588
asked on
How to let opendir read a directory in the Unix filesystem?
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:
<?php
$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 ";
}
closedir($dh);
}
}
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/MirrorDri ve/SharedI tems/Docum ents/) [function.opendir]: failed to open dir: Permission denied in /Library/WebServer/Documen ts/documen tserver/re addir.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. :)
TIA
That is not to hard in php, but my knowledge in unix permissions fails me.
Here is my code so far:
<?php
$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
}
closedir($dh);
}
}
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/MirrorDri
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. :)
TIA
ASKER
Well my script works with 777 so that is not the problem.
The problem is when I change to 755 it stops working so it is a permission problem.
I should also change my initial claim that I am running on a unix box, well I am sort of, it is an Apple Mac OS X Server 10.5.
What I am aiming for now is to add the user _www to the group that has access to this folder but that is easier said than done since all user/group management in done by the OpenDirectory database. So I need to fiddle with that through the CLI.
Not something I am comfortable with.
So if someone has input on that I am happy to receive that help. :)
The problem is when I change to 755 it stops working so it is a permission problem.
I should also change my initial claim that I am running on a unix box, well I am sort of, it is an Apple Mac OS X Server 10.5.
What I am aiming for now is to add the user _www to the group that has access to this folder but that is easier said than done since all user/group management in done by the OpenDirectory database. So I need to fiddle with that through the CLI.
Not something I am comfortable with.
So if someone has input on that I am happy to receive that help. :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Once you know your code works, start backing down the permissions.
chmod -R 0755 * is what you should be shooting for.
You may also want to try to add the apache service user to your user group.
https://www.experts-exchange.com/questions/24981151/Easy-permissions-question.html