Hey--
I'm trying to the file list of a dr off of a ftp server and I've come to the point where the thing should display the data...
So, there is a pretty big array which gets built up, then I want to extract, for example the file/dir names...
Please excuse the sloppiness of the code, for now 😉
<?php
$ftp_host = "localhost";
$ftp_user = "anonymous";
$ftp_password = "anonymous";
//Connect
echo "Connecting to $ftp_host via FTP...<BR>";
flush();
ob_flush();
$conn = ftp_connect($ftp_host);
$login = ftp_login($conn, $ftp_user, $ftp_password);
//
//Enable PASV ( Note: must be done after ftp_login() )
//
$mode = ftp_pasv($conn, TRUE);
//Login OK ?
if ((!$conn) || (!$login) || (!$mode)) {
die("FTP connection has failed !");
}
echo "Login Ok.<BR>";
flush();
ob_flush();
$mode = ftp_pasv($conn, TRUE);
//
//Now run ftp_nlist()
//
//$file_list = ftp_nlist($conn, "/");
//var_dump($file_list);
function itemize_dir($contents) {
foreach ($contents as $file) {
if(ereg("([-dl][rwxstST-]+).* ([0-9]*) ([a-zA-Z0-9]+).* ([a-zA-Z0-9]+).* ([0-9]*) ([a-zA-Z]+[0-9: ]*[0-9])[ ]+(([0-9]{2}:[0-9]{2})|[0-9]{4}) (.+)", $file, $regs)) {
$type = (int) strpos("-dl", $regs[1]{0});
$tmp_array['line'] = $regs[0];
$tmp_array['type'] = $type;
$tmp_array['rights'] = $regs[1];
$tmp_array['number'] = $regs[2];
$tmp_array['user'] = $regs[3];
$tmp_array['group'] = $regs[4];
$tmp_array['size'] = $regs[5];
$tmp_array['date'] = date("m-d",strtotime($regs[6]));
$tmp_array['time'] = $regs[7];
$tmp_array['name'] = $regs[9];
}
$dir_list[] = $tmp_array;
}
//return $tmp_array;
return $dir_list;
}
$buff = ftp_rawlist($conn, "/");
$items = itemize_dir($buff);
while (list ($line, $type, $rights, $number, $user, $group, $size, $date, $time, $name) = each($items)) {
print $name;
print "<BR>";
flush();
ob_flush();
}
//var_dump($items);
//close
ftp_close($conn);
?>
When I want to display the $line var, it works fine, however when I try to display any other var out of the array I just get an empty spot... (Of course the <BR>s still print fine)