2009-08-16 171 views
2

如何列出使用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

回答

1

我找到了一個很好的替代使用本地網絡路徑和正在使用的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); 
    } 
} 
3

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") 
?>