如何使用PHP在本地网络上遍历目录?

问题描述:

如何列出使用PHP的Windows共享内容?如何使用PHP在本地网络上遍历目录?

$SearchFolder = "\\\\192.168.1.100\\pdfoutput\\"; 

if (is_dir($SearchFolder)) 
{ 
    if ($Directory = opendir($SearchFolder)) 
    { 
     while (($File = readdir($Directory)) !== false) 
     { 
      if(filetype($SearchFolder.$File) == "file") 
      { 
       $this->Attachments[] = new Attachment($SearchFolder.$File); 
      } 
     } 
     closedir($Directory); 
    } 
} 

打印(opendir($ SearchFolder));出现此错误:

Warning: opendir(\192.168.1.100\pdfoutput) [function.opendir]: failed to open dir: No error in C:\Users\gary\Webserver\QuickMail\maildetails.php on line 227

这不按预期方式工作。有什么想法吗?

+1

您可以通过将问题映射到驱动器来解决问题吗? – Greg 2009-08-16 17:50:56

+0

你还使用PHP或Apache?如果你的谷歌“php unc路径”,你会得到一些关于权限的结果可能对你有帮助,但是它们在不同的web服务器上有所不同 – Greg 2009-08-16 17:57:19

+0

@Greg:这两个,当然?他在Windows上的Apache服务器上使用PHP语言(我假设)。至少,这两者不是相互排斥的。 – DisgruntledGoat 2009-08-16 18:09:52

我找到了一个很好的替代使用本地网络路径和正在使用的FTP服务器。这也很好,考虑到我需要从这个目录中显示一些图片。我使用的FTP服务器非常轻便,并且允许从整个LAN访问此目录,而不会出现任何安全或权限错误。

$SearchFolder = "ftp://192.168.0.104/PDFOutput/"; 

if (is_dir($SearchFolder)) 
{ 
    if ($Directory = opendir($SearchFolder)) 
    { 
     while (($File = readdir($Directory)) !== false) 
     { 
       if(filetype($SearchFolder.$File) == "file") 
       { 
         $this->Attachments[] = new Attachment($SearchFolder.$File); 
       } 
     } 
     closedir($Directory); 
    } 
} 

http://uk3.php.net/function.opendir查看用户对opendir功能的评论。看起来好像有些信息可以帮助你。具体来说,通过DaveRandom这段代码可以解决你的问题:

<?php 
// Define the parameters for the shell command 
$location = "\\servername\sharename"; 
$user = "USERNAME"; 
$pass = "PASSWORD"; 
$letter = "Z"; 

// Map the drive 
system("net use ".$letter.": \"".$location."\" ".$pass." /user:".$user." /persistent:no>nul 2>&1"); 

// Open the directory 
$dir = opendir($letter.":/an/example/path") 
?>