Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
394 views
in Technique[技术] by (71.8m points)

ftp - Separate file & directories in PHP

PHP code used for listing the files and directories.

$buff = ftp_nlist($conn_id,$dir );

$buff is an array of both files & directories.

Is there a way to get 2 seperate arrays , 1 contains just files and other just directories.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

From the documentation:

directory

The directory to be listed. This parameter can also include arguments, eg. ftp_nlist($conn_id, "-la /your/dir"); Note that this parameter isn't escaped so there may be some issues with filenames containing spaces and other characters.

So perform ftp_nlist twice: once providing arguments that give you only files, and then providing arguments that give you only directories. This will rely on the system where the FTP server sites.

Alternatively, you can employ this more verbose solution that uses ftp_chdir, or this one that uses ftp_size.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...