2013-07-12 26 views
0

使用FTP我想試試這個很難找到在PHP

鏈接的目錄:How to check using PHP FTP functionality if folder exists on server or not? 告訴我,如果我的代碼是正確的;

我似乎無法找到該文件夾​​,它呼應了失敗

樣品FTP帳戶

用戶:[email protected]

通:名@ pasword

FTP文件根目錄是:/ home/mywebsite/public_html/admin

我想查找的路徑文件夾是:public_html/admin/userfiles

我從的cPanel

if(is_dir('ftp://[email protected]:[email protected]@mywebsite.com/userfiles')) 
{ 
echo 'found'; 
} 
else 
{ 
echo 'failed'; 
} 

回答

0

設置管理員的路徑FTP帳戶路徑有一些先決條件使用「FTP://`這樣:

  • PHP指令allow_url_fopen必須設置爲真;
  • 目標服務器必須支持passive ftp

假設這兩點,你的URL必須準確。公約是ftp://name:[email protected]/folder。您的網址似乎在其中包含僞造的:[email protected]。如果

ftp://[email protected]:[email protected]@mywebsite.com/userfiles' 
         ^^^^^^ 
+0

他說密碼是:名@ pasw0rd – Matheno

+0

@Marijke,事實也的確如此,但名稱/密碼字符串看起來決然懷疑。它必須值得檢查。 – 2013-07-12 08:24:35

0

FTP功能檢查存在一個目錄

<?php 
function ftp_is_dir($dir) { 
    global $ftpcon; 
    // get current directory 
    $original_directory = ftp_pwd($ftpcon); 
    // test if you can change directory to $dir 
    // suppress errors in case $dir is not a file or not a directory 
    if (@ftp_chdir($ftpcon, $dir)) { 
     // If it is a directory, then change the directory back to the original directory 
     ftp_chdir($ftpcon, $original_directory); 
     return true; 
    } 
    else { 
     return false; 
    }   
} 
?>