4
從遠程服務器獲取ftp文件列表的最佳做法是什麼?PHP - 從遠程服務器獲取ftp列表的最佳做法是什麼?
1)使用FTP_CONNECT()函數
<?php
// set up connection
$conn = ftp_connect($ftp_server);
// login with username and password
$login = ftp_login($conn, $ftp_user_name, $ftp_user_pass);
// get contents of the current directory
$content = ftp_nlist($conn, ".");
// output content
var_dump($content);
?>
或
2)使用SCANDIR(),然後輸出文件列表與的print_r()
<?php
$path = "ftp://login:[email protected]";
$files = scandir($path);
print_r($files);
?>
兩種方法都輸出一個帶有ftp目錄/文件的數組。
你可以按照第一種方法,因爲這方法 是安全的連接到FTP和掃描 – Prasad