PHP Code Running on C: Drive, List Subfolders on E: Drive Permissions Issue

I am running php 5.4, IIS 7.5 on WinServer 2008 R2 box. I want to retrieve all subfolder names in a directory using PHP. I can successfully perform this task IF the target folder exists on the sam￿e drive as the php code, which is on c:. However, I need to retrieve subfolder names from the e:\ drive on the same server. I have the permissions properly set for IUSR and IIS_IUSRS (read & exe, modify) for the target and parent folders but of course I don’t have those permissions all the way to the root of e:\ drive. Using scandir(), I get “Access is denied. (code: 5)” but I have tried glob() and RecursiveDirectoryIterator to no avail. I have not been able to find a solution or an example so perhaps it is not possible. Any recommendations are greatly appreciated.

"" is the escape character in PHP - you can’t use it in double quotes.

file_get_contents(“e:\path\to\file”) will search the file system for “e:athoile”. Either use single quotes or turn the directory separator around, PHP under windows allows “e:/path/to/file”

You can also escape the \ as \\

First of all, thanks for your response Michael as well as felgall - I appreciate it. My bad on using the backslash in my original post. I am designating my path in my code as follows:

// This will work since target folder resides on same drive (c:/ drive) as the php code (c:/inetpub)
$shared_drive_path = "c:/path_name/";

// This will NOT work since target folder resides on different drive (e:/ drive) than the php code (c:/inetpub)
$shared_drive_path = "e:/path_name/"; // permissions error

Here is an example of my code using the above path which works if target folder is on c:/ drive, but will not work when target folder is on a different drive (e.g., e:/ drive). The php code resides on the c:/ drive.

// Cycle through parent folder and retrieve all folder names
foreach(glob($shared_drive_path . '*', GLOB_NOSORT) as $fullpath_folder){
    // Extract the folder name from full path for each folder detected 
    $folder_name = substr(strrchr(rtrim($fullpath_folder, '/'), '/'), 1);
    // Perform an action/check here on folder name retrieved
}

I simply cannot find any examples of this where the target folder to scan is on a different drive. Keep in mind the e:/ drive is not a network drive, just one of the three drives on the server, with c:/ containing the php code under the inetpub/wwwroot.

Well, I’m out of ideas. I avoid Windows except for gaming. I’ve managed to get PHP up and running on IIS once, and it’s not an experience I’m keen on repeating.

Maybe set up a shortcut PHP could follow?

Understood. Thanks anyways. Our environment is Windows so I gotta make due.

Out of curiosity what happens when you give Everyone read access?

Meaning give Everyone read access to the root of the E: drive?

Yes. Just curious if that works. Is it truly a permission issue. If you grant Read to Everyone, then that should allow your script to run, proving it is a permission problem (if it still fails, something else is still going on)

I will try that. I can always revert the permissions after the test.

Yes, just want to confirm, I want to prove it can work, before we dive down into what permissions does it really need. I don’t expect or want you to keep Read access for Everyone. I simply want to know, it works that way and when we limit who has access, it stops working :smile:

I appreciate the follow-up. Since I haven’t find any examples where the php code runs on one Windows drive but searches a different Windows drive, I am wondering if it is even possible.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.