示例:
awesome_dksd.php
awesome_dfkdde.php
dklf_dlsfd.php
示例路径:public_html / folder /
我如何使用php搜索那个ftp的一侧以获取以awesome_开头的文件我能够通过ftp_connect()
进行连接我无法找到一个函数或任何方法在ftp中搜索一个文件以awesome_
开始?
谢谢
答案 0 :(得分:1)
使用ftp_nlist
获取所有文件的列表
http://php.net/manual/en/function.ftp-nlist.php
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// get contents of the current directory
$contents = ftp_nlist($conn_id, ".");
然后使用$contents
循环遍历foreach
或使用您最喜欢的正则表达式方法过滤掉任何不以 awesome _ 开头的内容!
答案 1 :(得分:0)
你可以尝试类似的东西(调整味道和php版本)
$ftpStream = ftp_connect (...);
// file listing
$files = ftp_nlist ( $ftpStream , string $directory );
// filters array with function that search position of string
$array = array_filter($array, function($value) {
return !(strpos($value, 'awesome') > 0);
});
问候。