开发者

PHP - FTP list files

开发者 https://www.devze.com 2023-02-14 20:33 出处:网络
I am new to the FTP feature of PHP. I have a dire开发者_如何学Goctory within my FTP location called documents. I need to get the folders/files within another directory. So like this basically:

I am new to the FTP feature of PHP. I have a dire开发者_如何学Goctory within my FTP location called documents. I need to get the folders/files within another directory. So like this basically:

root/documents/Ryan-Hart/ <-all-files/folders-here

So how can I show and link to these from PHP. I have tried this:

$name = "Ryan-Hart";

$conn_id = ftp_connect($ftp_server);

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

print_r(ftp_nlist($conn_id,"/documents/$name"));

But that comes out in array. How can a echo out the name (plus extension) of file and link to them?


Are you looking for something like that?

$arr= ftp_nlist($conn_id,"/documents/$name");

foreach ($arr as $value)
{
  echo '<a href="'.$value.'">'.basename($value).'</a>';
}
0

精彩评论

暂无评论...
验证码 换一张
取 消