English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I am using PHP to create a web-based front end for an FTP server. I currently get the files/subfolders listed in a specific folder using:

$mylist = array();
$mylist = $newftp->get_file_list($mydir);
$files = $newftp->parse_ftp_rawlist($mylist);

I then want to be able to sort this array so that the folders are listed first and then the files alphabetically.

Please help me.

2007-01-08 02:26:06 · 4 answers · asked by The Oracle 2 in Computers & Internet Programming & Design

4 answers

I'm afraid there is no easy answer for this, but they do discuss a couple functions that seem to return arrays of the directories, files and links. http://us3.php.net/manual/en/function.ftp-rawlist.php
Also take a look at http://us3.php.net/manual/en/function.ftp-nlist.php
The examples there should be able to help you do it but I'm afraid there isn't a quick sort or pre-created command that I know of. I hope this helps.

Good Luck

2007-01-08 03:02:22 · answer #1 · answered by djlazi 2 · 1 0

How do you get the file list?

Assuming you make a system call, you can do this by making two instead of one system call. To get all the directories do something like

ls -ald */ or ls -l | grep "^d"

and then you can get all the files using

ls -l | grep "^-".

I am assuming you do not have any symbolic links in your ftp folders.

or I guess you could do with ls -S

2007-01-10 07:32:59 · answer #2 · answered by Sanjay 3 · 0 0

properly this 48ff4b7ebe8ad623c55f75a29433c29ght be an eval() situ48ff4b7ebe8ad623c55f75a29433c29ion i think of th48ff4b7ebe8ad623c55f75a29433c29 works yet i'm no longer too useful and ca48ff4b7ebe8ad623c55f75a29433c29t say i'm the b48ff4b7ebe8ad623c55f75a29433c29t with eval()

2016-11-27 19:34:41 · answer #3 · answered by ? 4 · 0 0

u can do that easily

foreach($files as $file)
{
if( is_dir( $file )) $Myfolders[] = $file;
else $Myfiles[] = $file;
}

2007-01-11 09:59:53 · answer #4 · answered by Dr.Math 1 · 0 0

fedest.com, questions and answers