2011-02-16 27 views
0

我試圖讓php腳本連接到afp服務器並獲取目錄列表(每個文件的大小)。服務器在我們的辦公室是本地的,但我無法在afp服務器端創建腳本。在我的機器上,我使用這樣的東西:使用PHP連接到遠程afp服務器

$filesInDir = array(); 
$filesInMySQL = array(); 

if (is_dir($uploadDir)) { 
    $dh = opendir($uploadDir); 
    if ($dh) { 
     $file = readdir($dh); 

     while ($file != false) { 
      $path = $uploadDir . "/" . $file; 
      $type = filetype($path); 

      if ($type == "file" && $file != ".DS_Store" && $file != "index.php") { 
       $filesInDir[] = $file; 
      } 

      $file = readdir($dh); 
     } 

     closedir($dh); 
    } else { 
     echo "Can't open dir " . $uploadDir; 
    } 
} else { 
    echo $uploadDir . " is not a folder"; 
} 

但我無法連接到afp服務器。我已經研究過的fopen它不允許AFP,我不認爲它會允許目錄列表:

opendir("afp://ServerName/path/to/dir/"); 

Warning: opendir() [function.opendir]: Unable to find the wrapper "afp" - did you forget to enable it when you configured PHP? in... 
Warning: opendir(afp://ServerName/path/to/dir/) [function.opendir]: failed to open dir: No such file or directory in...` 

我不希望看到文件是否存在,但要獲得整個目錄列表。最後,我還必須將文件遠程複製到輸出目錄中。

例如。

mkdir afp://ServerName/output/output001/ 
cp afp://ServerName/path/to/dir/neededfile.txt afp://ServerName/output/output001/ 
+1

有趣的問題,但我從來沒有見過在野外法新社封套PHP的,所以我不認爲我的呼吸。 ;) – deceze 2011-02-16 04:23:29

+1

我以前見過SMB封裝器,但是...如果你可以在有問題的共享器上使用smb,那麼你可以使用它... – prodigitalson 2011-02-16 04:28:27

回答

0

我上的Mac Mini的發展,所以我意識到我可能只是安裝AFP共享,並使用readdir的。我不得不使用下面安裝的驅動器:

sudo -u _www mkdir /Volumes/idisk 
sudo -u _www mount_afp -i afp://<IP>/sharename/ /Volumes/idisk/ 

進一步詳情here