Log in

View Full Version : opendir() help



Westy-php-learner
01-31-2011, 05:18 PM
I am learning php and I'm working on displaying information from a directory. I understand the concept and that you need it as part of the script, but what I'm having trouble with is what does opendir() return when you use it? For example - if ($dh = opendir($dir)) - what is stored to $dh - a number, true or directory name? Does it even matter - because if you can't access the directory opendir returns false. If opendir returns false could that relate to directory access rights under windows?

I use windows for my web server and before I get too involved in a project to list directories and files I wanted to make sure I can stop a user from accessing a directory. Here's my inital thinking of when someone clicks on a directory that they are not able to access.

if (opendir(c:\images\today) != false);
exit ("Can't access directory"); or a die("You are not authorized")
else

I have looked at many different scripts that put the directory listing into an array. When the directories are scanned, if opendir cannot open the directory will it not put it into the array?

Thanks for your help.

traq
01-31-2011, 09:18 PM
it returns a "resource" on success - which is not something that evaluates to "true" or "dirname/" or whatever, but is used by other filesystem functions to access the directory.