Link to home
Start Free TrialLog in
Avatar of Marco van Beek
Marco van BeekFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Accessing mapped drive from php / iis

Hi,

I am using php on IIS7 to read data from a MSSQL database. One of the fields have a file path in it to an image file which I then need to access.

The problem is that the path has a mapped drive letter in it. I know I can access the file using the UNC name (i.e. "\\server\share\folder\file") but the users are accessing the drive as their W:\ drive, and so when they update the database, the field value ends up being "W:\folder\file", which php does not appear to be able to access. I assume this is because the user that php runs as (which according to phpinfo seems to be the computer account (i.e. "server$") does not have a drive mapping for W:\.

So while I could write a bit of code that took off the W:\ and replaced it with the UNC path, that isn't really bulletproof.

So my question is, does anyone know of a way to get a shared drive mapping into the profile of the php user, and can it be done safely? To be honest, I have got around this problem in the past by making W:\ a "real" drive on the server, so the local and mapped paths were identical, but I can't do this on this server.

Alternatively any other clever suggestions (and no, search and replace the values in the database is not an option).
Avatar of Aaron Tomosky
Aaron Tomosky
Flag of United States of America image

I try to save these values as /folder/file in the db. Then I have a server variable for the doc root (\\server\share)
This keeps things flexible with relative paths instead of absolute.
Avatar of Marco van Beek

ASKER

Sorry, as I mentioned, search and replace the values in the database is not an option, and neither is changing the way users already work. I have to use what is in the database, and worse, what might be in the database in the future.
ASKER CERTIFIED SOLUTION
Avatar of Aaron Tomosky
Aaron Tomosky
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The user that IIS and PHP operates under (IUSR...) is restricted to the local machine and can't be given permissions on another machine.  In another question, someone said that a 'mapped' drive solved the problem for them because it made the drive 'local' but in a different question, someone else never got that to work.

What do you mean "by making W:\ a "real" drive on the server"?
I had a similar probelm on an Intranet site I am developing.
I was not able to find a bullet-proof solution.
My work-around was to schedue a job each night which copies the images I need from my mapped drive to a folder on my web server.  That way, I don't need to worry about the mapped drive at all.
Re "What do you mean "by making W:\ a "real" drive on the server"? ".

On that particular project I set up a dedicated partition for the data, and set the drive letter to be W: I then shared it at the root level (eg \\SERVER\W$), and mapped W:\ to it on the client computers, so as far as the web server was concerned, W was a real drive that it could access.

But I can't do this on this project. :-(
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So the solution is either to use a separate partition for the data that can be given the same local drive letter as the clients use for the mapping, or to use a replacement script. I used an array that allows me multiple entries like "W:" => "\\SERVER\SHARE", and then my script loops through and replaces any matching drive letters with the UNC path. There seems to be short delay in the whole process (~1sec), over accessing local drive, which I assume is caused by going over the network.