开发者

PHP: Opendir a Network Drive of a different domain

开发者 https://www.devze.com 2023-04-03 08:29 出处:网络
So I\'ve got two servers (Webserver and NAS on the same domain (domainB)). I\'ve got a PHP script on the Webserver (domainB) which list a specific directory on the NAS.

So I've got two servers (Webserver and NAS on the same domain (domainB)).

I've got a PHP script on the Webserver (domainB) which list a specific directory on the NAS.

When I execute the script on my webserver it works. But if I execute the script from a different domain (domainA), for example from my local machine, it doesn't work. It seems it stops at the opendir() line.

I've XAMPP installed on my machine and if I execute that script from my local webserver it also works.

The 'testfolder' is a shared folder on the NAS and read permission is granted to everyone.

Does anyone know what the problem is?

Code:

$dir = "//NAS.domainB.test/testfolder";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file =开发者_如何转开发 readdir($dh)) !== false) {
            echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
        }
        closedir($dh);
    }
}


The problem may be with access restrictions of course. Try put

error_reporting(E_ALL);

at first line of your code.


I probably found the source of my problem and the solution of course.

I didn't work because my IIS was using an impersonator (probably the IUSR User) and he has no permissions on my NAS.

More Info: http://www.php.net/manual/en/install.windows.iis7.php (see Impersonation and file system access).

Solution: I set the folder with the script as an application on my IIS and configured to connect as a specific user with permission on the NAS.

It would probably also work if I would give the IUSR User read-permission on the NAS.

0

精彩评论

暂无评论...
验证码 换一张
取 消