0
I have the following code that connects on an ftp and back a list. But I can’t get him to build a table with that list. Someone knows how to do?
$ftp_server = "ftp.site.com.br";
$ftp_user = "USER_FTP";
$ftp_pass = "SENHA_FTP";
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "<br>$ftp_server";
} else {
echo "Couldn't connect as $ftp_user\n";
}
ftp_pasv($conn_id, TRUE);
$dir = "/diretorio/";
function filecollect($dir,$filelist) {
global $conn_id; //Retorna FTP
$files = ftp_nlist($conn_id,$dir); //Retorna o Directory
foreach ($files as $file) {
$isfile = ftp_size($conn_id, $file);
if($isfile == "-1") { //É um arquivo ou diretorio?
$filelist = filecollect($dir.'/'.$file,$filelist,$num); //Se for diretório, faça "filecollect()"
}
else {
$filelist[(count($filelist)+1)] = $file; //Se não,adicione a uma arquivo para a lista
}
}
return $filelist;
}
$list = filecollect($dir,$filelist);
$list = implode("<br>$ftp_server", $list);
echo $list;
ftp_close($conn_id);
I know it has some flaws but the main thing is to turn this data into a table.
Thanks for your help.
Data comes back from ftp as array or as object?
– Adriano Luz
@Adrianoluz with $list = implode("<br>$ftp_server", $list); back a String, if I take the implode and put print_r($list) back an array
– Wagner Viana
And this array have you tried to var_dump to see what’s in it? If it returns an array with the table fields just give a foreach and mount the table
– Adriano Luz