I have tried adding the code that you helped the other guy with but this doesn’t appear to do what I need.
It is seperating the files from the folders but the files are still being listed in size order and not alphabetical order and the folders are being listed last.
This is the complete code listing for what I’m trying to do. I hope this is not too garbled for you to read:
[code]
<?php
session_start();
//BS 20/10/06
//Code will assign the inputs from index.php to the SESSION Varibles.
if ($_POST['Connect']) {
foreach($_POST as $key => $value) {
if ($key == "") {
echo "All form fields are required.";
exit();
}
}
$_SESSION['ftp_label'] = $_POST['ftp_label'];
$_SESSION['ftp_server'] = $_POST['ftp_server'];
$_SESSION['ftp_user_name'] = $_POST['ftp_user_name'];
$_SESSION['ftp_user_pass'] = $_POST['ftp_user_pass'];
$_SESSION['ftp_port'] = $_POST['ftp_port'];
}
//Assign SESSION varibles to name varibles for easy accessing.
$ftp_label = $_SESSION['ftp_label'];
$ftp_server = $_SESSION['ftp_server'];
$ftp_user_name = $_SESSION['ftp_user_name'];
$ftp_user_pass = $_SESSION['ftp_user_pass'];
$ftp_port = $_SESSION['ftp_port'];
//Adds the class page so that functions can be used
require_once('classes/class.php');
//Puts the header on the top of the page
require_once('includes/header.php');
//Establish new connection
$newftp = new myftp;
$result = $newftp->connect($ftp_server, $ftp_user_name, $ftp_user_pass, $ftp_port);
$ftp_remote_dir = "/";
$backdir = substr($ftp_remote_dir, 0, strrpos($ftp_remote_dir, "/"));
echo "
";
$v="_zip";
function cmp($a,$b) {
if(is_dir($a) && is_dir($b)) return strcmp($a,$b);
elseif(!is_dir($a) && !is_dir($b)) return strcmp($a,$b);
elseif(is_dir($a)) return -1;
else return 1;
}
//A set of nested IF statements to call functions from class.php which will respectively
//Get a remote directory path, save a file (this section has been replaced),
//delete entire directories, create directories, delete fies, and upload files.
if (!$result){
$mydir = $newftp->get_dir();
if ($_GET['dir']) {
$ftp_remote_dir = $_GET['dir'];
$ftp_remote_dir = preg_replace('/(../)+/i', "/", $ftp_remote_dir);
$mydir = $newftp->change_dir($ftp_remote_dir);
$mydir = $ftp_remote_dir;
} else {
$ftp_remote_dir = $mydir;
}
if ($_GET['action'] == "save") {
$fp = tmpfile();
fwrite($fp, $_POST['content']);
rewind($fp);
$uploadfile = $newftp->upload_open_file($_POST['file'], $fp);
}
if ($_GET['action'] == "rename") {
$rename = $newftp->rename_file($_POST['oldname'], $_POST['newname']);
}
if ($_GET['action'] == "del_dir") {
$deldirectory = $newftp->del_dir($_GET['delete']);
}
if ($_GET['action'] == "newdir") {
$newdir = $newftp->new_dir($_POST['dir_name']);
}
if ($_GET['action'] == "delete") {
$deletefile = $newftp->delete_file($file);
}
if ($_GET['action'] == "upload") {
$destination_file = $_FILES['file']['name'];
$source_file = $_FILES['file']['tmp_name'];
$uploadfile = $newftp->upload_file($destination_file, $source_file, FTP_BINARY);
}
//Download files and folders to an array...
$backdir = substr($ftp_remote_dir, 0, strrpos($ftp_remote_dir, "/"));
if($backdir == "") { $backdir = "/"; }
$mylist = array();
$mylist = $newftp->get_file_list($mydir);
usort($mylist,cmp);
$files = $newftp->parse_ftp_rawlist($mylist);
$total = count($files)-1;
$x = -1;
echo "
You are curently in folder: /$ftp_user_name$mydir
";
echo "
![]()
";
echo "
![]()
";
echo "
";
foreach($files as $data) {
$x+=1;
if ($data['perms'] == "Attributes") {
//Display the folders/files in a table with the actions that can be performed next to them
echo "
|
$data[name] |
$data[size] |
Added |
Select files to Download |
Delete? |
";
} elseif ($data['is_dir'] == TRUE) {
if ($mydir == "/") {
$target = $mydir.$data['name'];
} else {
$target = $mydir."/".$data[name];
}
//The object is a folder so the folder options are diplayed
echo "
$x |
$data[name]
|
|
$data[date] |
|
![DELETE?]() |
";
} elseif ($data['is_link']) {
echo "
$x |
$data[name]
|
".round($data['size'] / 1024)."Kb ($data[size] bytes) |
$data[date] |
|
![DELETE?]() |
";
} else {
//The object is as file so the download option links to download.php and the size is displayed.
echo "
$x |
";
$ext = strrchr($data[name],".");
$imagetype = $ext;
if ($ext == ".jpg") {
$imagetype = "jpg";
} elseif ($ext == ".bmp"){
$imagetype = "bmp";
} elseif ($ext == ".zip"){
$imagetype = "zip";
} elseif ($ext == ".mxd"){
$imagetype = "mxd";
} elseif ($ext == ".png"){
$imagetype = "png";
} elseif ($ext == ".gif"){
$imagetype = "gif";
} elseif ($ext == ".txt"){
$imagetype = "txt";
} elseif ($ext == ".xls"){
$imagetype = "xls";
} elseif ($ext == ".pdf"){
$imagetype = "pdf";
} elseif ($ext == ".PDF"){
$imagetype = "pdf";
} elseif ($ext == ".tif"){
$imagetype = "tif";
} elseif ($ext == ".tiff"){
$imagetype = "tif";
} elseif ($ext == ".ppt"){
$imagetype = "ppt";
} elseif ($ext == ".loc"){
$imagetype = "loc";
} elseif ($ext == ".htm"){
$imagetype = "htm";
} elseif ($ext == ".html"){
$imagetype = "htm";
} elseif ($ext == ".exe"){
$imagetype = "exe";
} elseif ($ext == ".mig"){
$imagetype = "mig";
} elseif ($ext == ".sgy"){
$imagetype = "sei";
} elseif ($ext == ".stk"){
$imagetype = "sei";
} elseif ($ext == ".las"){
$imagetype = "sei";
} elseif ($ext == ".tr2"){
$imagetype = "sei";
} elseif ($ext == ".spt"){
$imagetype = "spt";
} elseif ($ext == ".doc"){
$imagetype = "doc";
} elseif ($ext == ".jpeg"){
$imagetype = "jpg";
} elseif ($ext == ".shp"){
$imagetype = "shp";
} elseif ($ext == ".xml"){
$imagetype = "xml";
} elseif ($ext == ".mov"){
$imagetype = "mov";
} elseif ($ext == ".avi"){
$imagetype = "mov";
} else $imagetype = "unk";
echo" $data[name]
|
";
$g=($data['size']);
if ($g < 1024)
{$z= $g.' Bytes';
} elseif ($g < 1024*1024)
{$z= round(($g / 1024)). 'KB';
} elseif ($g < (1024*1024*1024))
{$z= round((($g/1024)/1024)).' MB';
} elseif ($g >(1024*1024*1024*1024))
{$z= round(((($g/1024)/1024)/1024)).' GB';
} else $z= $g.' Bytes';
echo" $z |
$data[date] |
|
![DELETE?]() |
";
}
}
echo "
";
echo "";
echo "
![]()
";
echo "
![]()
";
echo "
";
// The upload to current folder link and create new folder are shown at the bottom.
echo"
Please be patient while your file uploads.
";
echo "
Zip selected files for download
|
Upload file to Current Folder
|
Create a New Folder
|
";
// Once the code has been completed the link to the FTP server is disconnected
$newftp->ftp_disconnect();
} else {
echo "No Connection Established
";
}
// The code that is written in footer.php is displayed
require_once('includes/footer.php');
?>[/code]
I’m sorry for dumping out all of the code for the page, but hopefully this will help you to see the problem and suggest a way I can resolve it?
Many thanks for you continued help and advice. Ben.