php windows下php访问网络路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1153824/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
php access network path under windows
提问by Max
within PHP (XAMPP) installed on a Windows XP Computer Im trying to read a dir which exists on a local network server. Im using is_dir()to check whether it is a dir that I can read.
在 Windows XP 计算机上安装的 PHP (XAMPP) 中我试图读取本地网络服务器上存在的目录。我is_dir()用来检查它是否是我可以阅读的目录。
In Windows Explorer I type \\\server\dirand that dir is being shown.
When I map a network drive a can access it with z:\diras well.
在 Windows 资源管理器中,我键入\\\server\dir并显示该目录。当我映射网络驱动器时,也可以访问它z:\dir。
In PHP I have that script:
在 PHP 我有那个脚本:
<?php if( is_dir($dir){ echo 'success' } ) ?>
For $dirI tried:
因为$dir我试过:
/server/dir//server/dir\server\dir\\server\dir\\\\server\\dir
/server/dir//server/dir\server\dir\\server\dir\\\\server\\dir
and
和
z:\dirz:\\dirz:/dirz://dir
z:\dirz:\\dirz:/dirz://dir
But I never get success? Any idea? thx
但我从来没有成功过?任何的想法?谢谢
采纳答案by Max
I solved it by changing some stuff in the registry of the server as explained in the last answer of this discussion:
我通过更改服务器注册表中的一些内容来解决它,如本讨论的最后一个答案所述:
http://bugs.php.net/bug.php?id=25805
http://bugs.php.net/bug.php?id=25805
Thanks to VolkerK and Gumbo anyway! I love stackoverflow and their great people who help you so incredibly fast!!
无论如何都要感谢 VolkerK 和 Gumbo!我喜欢 stackoverflow 和他们很棒的人,他们可以如此快速地帮助你!!
EDIT (taken from php.net):
编辑(取自 php.net):
The service has limited access to network resources, such as shares and pipes, because it has no credentials and must connect using a null session. The following registry key contains the NullSessionPipes and NullSessionShares values, which are used to specify the pipes and shares to which null sessions may connect: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters Alternatively, you could add the REG_DWORD value RestrictNullSessAccess to the key and set it to 0 to allow all null sessions to access all pipes and shares created on that machine.`
该服务对网络资源(例如共享和管道)的访问受到限制,因为它没有凭据并且必须使用空会话进行连接。以下注册表项包含 NullSessionPipes 和 NullSessionShares 值,用于指定空会话可以连接到的管道和共享: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters 或者,您可以将 REG_DWORD 值 RestrictNullSessAccess 添加到该键并将其设置为 0 以允许所有空会话访问在该机器上创建的所有管道和共享。`
add RestrictNullSessAccess=0 to your registery.
将 RestrictNullSessAccess=0 添加到您的注册表中。
回答by VolkerK
You probably let xampp install apache as service and run the php scripts trough this apache. And the apache service (running as localsystem) is not allowed to access the network the way your user account is.
您可能让 xampp 将 apache 安装为服务并通过此 apache 运行 php 脚本。并且 apache 服务(作为localsystem运行)不允许以您的用户帐户的方式访问网络。
A service that runs in the context of the LocalSystem account inherits the security context of the SCM. The user SID is created from the SECURITY_LOCAL_SYSTEM_RID value. The account is not associated with any logged-on user account.
This has several implications:
...
* The service presents the computer's credentials to remote servers.
...
在 LocalSystem 帐户的上下文中运行的服务继承 SCM 的安全上下文。用户 SID 是根据 SECURITY_LOCAL_SYSTEM_RID 值创建的。该帐户未与任何登录的用户帐户相关联。
这有几个含义:
...
*该服务将计算机的凭据提供给远程服务器。
...
You can test this by starting the apache as console application (apache_start.bat in the xampp directory should do that) and run the script again. You can use both forward and backward slashes in the unc path. I'd suggest using //server/share since php doesn't care about / in string literals.
您可以通过将 apache 作为控制台应用程序启动(xampp 目录中的 apache_start.bat 应该这样做)并再次运行脚本来测试这一点。您可以在 unc 路径中使用正斜杠和反斜杠。我建议使用 //server/share 因为 php 不关心字符串文字中的 / 。
<?php
$uncpath = '//server/dir';
$dh = opendir($uncpath);
echo "<pre>\n";
var_dump($dh, error_get_last());
echo "\n</pre>";
回答by Gumbo
Try the file:URI scheme:
尝试file:URI 方案:
file://server/dir
file:///Z:/dir
The begin is always file://. The next path segment is the server. If it's on your local machine, leave it blank (see second example). See also File URIs in Windows.
开始总是file://。下一个路径段是服务器。如果它在您的本地机器上,请将其留空(参见第二个示例)。另请参阅Windows 中的文件 URI。
回答by Jams
Yes, I know this is an old post, but I still found it, and if anyone else does... On Windows, with newer servers, verify the SMB is installed and enabled on the target machine.
是的,我知道这是一篇旧帖子,但我仍然找到它,如果其他人找到了...在 Windows 上,使用较新的服务器,验证 SMB 已安装并在目标机器上启用。

