在Windows XP计算机上安装的PHP(XAMPP)中,试图读取本地网络服务器上存在的DIR。我在用着 is_dir() 检查是否可以阅读是DIR。

在Windows Explorer中我输入 \\\server\dir 并且正在显示那个dir。当我映射网络驱动器时,A可以使用 z:\dir 也是。

在PHP中,我有那个脚本:

<?php if( is_dir($dir){ echo 'success' } ) ?>

为了 $dir 我试过了:

  • /server/dir
  • //server/dir
  • \server\dir
  • \\server\dir
  • \\\\server\\dir

  • z:\dir
  • z:\\dir
  • z:/dir
  • z://dir

但是我从来没有成功吗?任何想法?谢谢

有帮助吗?

解决方案

我通过更改服务器注册表中的一些内容来解决它,如本讨论的最后一个答案所述:

http://bugs.php.net/bug.php?id=25805

感谢Volkerk和Gumbo!我爱Stackoverflow及其伟大的人,他们如此快速地帮助您!!

编辑(取自php.net):

该服务对网络资源(例如共享和管道)的访问有限,因为它没有凭据,并且必须使用零会话连接。 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_MACHINESYSTEMCurrentControlSetServicesLanmanServerParameters Alternatively, you could add the REG_DWORD value RestrictNullSessAccess to the key并将其设置为0,以允许所有NULL会话访问该机器上创建的所有管道和共享。

在您的寄存器中添加drillictNullSessAccess = 0。

其他提示

您可能让XAMPP安装Apache作为服务,并运行PHP脚本此Apache。和apache服务(以 当地系统)不允许像用户帐户那样访问网络。

在本地系统帐户上下文中运行的服务继承了SCM的安全上下文。用户SID是从Security_local_system_rid值创建的。 该帐户与任何记录的用户帐户无关.
这有几个含义:
...
   * 该服务将计算机的凭据显示给远程服务器.
...

您可以通过启动APACHE作为控制台应用程序(XAMPP目录中的Apache_start.bat应该执行此操作)并再次运行脚本来测试。您可以在UNC路径中使用前向和后斜线。我建议使用//服务器 /共享,因为PHP在字符串文字中不在乎 /。

<?php
$uncpath = '//server/dir';
$dh = opendir($uncpath);
echo "<pre>\n";
var_dump($dh, error_get_last());
echo  "\n</pre>";

尝试 file: URI计划:

file://server/dir
file:///Z:/dir

开始总是 file://. 。下一个路径段是服务器。如果在您的本地计算机上,请将其留空(请参见第二个示例)。也可以看看 在Windows中文件uris.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top