views:

235

answers:

1

Hello all,

I have mapped a network drive to a computer in my home network. Now I am trying to access it via PHP - I did this quick test:

echo opendir('Z:\\');

This gives me:

Warning: opendir(Z:\) [function.opendir]: failed to open dir: No error in C:\wamp\www\webs\tester-function.php  on line 3

What have I done wrong here?

I don't want my users typing in the UNC path so is there a way to get the UNC path for them and maybe that will work when I try to access it? This is possible in Microsoft languages but I am not sure how to get PHP to do this - maybe using a cmd.exe command?

Please note, the mapped drive does exist as I can see it and I can access it. It also does not appear to be a permissions problem as I am assuming it would of complained about this IF it could access that drive...right?

Thanks all for any help

+2  A: 

The User Contributed Notes to opendir() have this:

I was trying to access network drives using this opendir function. I read so many posts saying that it was almost impossible to access a network drive and finally, I found the answer; there are 2 steps to be followed to access a network drive with PHP either on the same machine or another machine.

in this case, the user rights seemed indeed to be the problem, which can be different from your rights depending on what user PHP / the web server are running on.

Pekka
That's interesting! Apache runs as the user 'SYSTEM' - in the permissions settings - the mapped drive has the user 'SYSTEM' to be able to read the drive. In this way, I have done those two steps and it still doesn't work. Maybe I misunderstood something?!
Abs
How did you create the drive map? Creating the drive map for your account doesn't mean the webserver's process/account gets the same mapping.
VolkerK
@Abs hard to tell. Maybe try to run the service under a specific user account as outlined in the linked comment, just to see whether it works that way?
Pekka
@Pekka - I will try this. @VolkerK - I used the normal map drive network drive wizard logged in as me "Abs-PC". Once I did this, there were other users and user-groups that got permissions set (all to at least read) one of which is SYSTEM, which the httpd service happens to run under.
Abs
@Abs: Take a look at http://msdn.microsoft.com/en-us/library/aa363908%28v=VS.85%29.aspx . You've created a network drive in the _local_ MS-DOS device namespace.
VolkerK