Q:

How to access mapped network drives using PHP running in IIS

I have this web system in PHP (5.6) and is running in IIS 8.5 Windows Server 2012 R2.
What I wanted to do is list all the files in a directory. The directory that I'm reading is a mapped network drive of a shared folder of another server (Y:\sharedfolder). When I execute command dir of the network drive, it is not seen by the php code
I have searched here in site and saw a lot of possible solutions but nothing work on my end. I'm not sure I'm doing them correctly. So I'll share my current settings here.
When I ran whoami in CLI, I get "pc_name\administrator". when I execute it in code, I get "iis apppool\cs2".
The mapped network drive (Y:\sharedfolder) is shared to the following:

Everyone
SYSTEM
Administrator (pc_name\Administrator)
Administrators (pc_name\Administrators)
IIS_IUSRS (pc_name\IIS_IUSRS)
CS2 (iis apppool\cs2)

My IIS Settings are the following:
[Authentication]

Anonymous Authentication (Enabled, Credentials: Application pool identity)
ASP.NET Impersonation (Disabled)
Forms Authentication (Disabled)

[Application Pools]

CS2 (.NET CLR v4.0, Managed pipeline mode: Integrated, Identity: ApplicationPoolIdentity, Load User Profile: True)
DefaultAppPool (.NET CLR v4.0, Managed pipeline mode: Integrated, Identity: ApplicationPoolIdentity, Load User Profile: True)

[Fast CGI Settings]

C:\php\php-cgi.exe (Protocol Tcp)

[Sites: CS2]

Site name: CS2
Application Pool: CS2
Physical Path: C:\inetpub\wwwroot\cs2
Connect as 'administrator' 

These are all my settings yet I still couldn't access the Mapped network drive. Is there a missing or incorrect setting in my IIS?

A:

Not sure if it works fine with mapped drive,IIS and PHP. But it is recommended to use UNC path instead.
When you run whoami, your application exectued it as your login user. However, when you host web app in IIS. The app run under application pool identity and access file via anonymous user.
If your shared folder server and IIS server are in the same domain. Then you could try to set application pool identity to a domain account who has enough permission to access the folder. Then please go to anonymous authentication and edit it to use Application pool idenity.
If you your shared folder server and IIS server are two separate workstation. Then you may need to create a user with same username and password. Then Grant the user read/write permission to access the UNC path. Finally you only have to set both anonymous user and application pool identity to this user.

