ftp_nlist

(PHP 4, PHP 5, PHP 7, PHP 8)

ftp_nlist返回给定目录的文件列表

说明

ftp_nlist(FTP\Connection $ftp, string $directory): array|false

参数

ftp

FTP\Connection 实例。

directory

指定要列表的目录。本参数接受带参数的形式,例如:ftp_nlist($ftp, "-la /your/dir");;注意此参数不对传入值做处理,在目录或者文件名包括空格或特殊的情况下,可能会存在问题。

返回值

如果成功则返回给定目录下的文件名组成的数组,否则返回 false

更新日志

版本 说明
8.1.0 现在 ftp 参数接受 FTP\Connection 实例,之前接受 资源(resource)

范例

示例 #1 ftp_nlist() 示例

<?php

// set up basic connection
$ftp = ftp_connect($ftp_server);
$login_result = ftp_login($ftp, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$ftp) || (!$login_result)) {
die(
"FTP connection has failed !");
}

// get contents of the root directory
$contents = ftp_nlist($ftp, "/");

// output $contents
var_dump($contents);

?>

以上例程的输出类似于:

array(3) {
  [0]=>
  string(11) "public_html"
  [1]=>
  string(10) "public_ftp"
  [2]=>
  string(3) "www"

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top