Array for Table PHP

0

I have the following code that connects to an ftp and back a list. But I can not get him to mount a Table with this list. Does anyone know how to do it?

$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 there are some flaws but the main thing is to turn this data into a table.

Right now, thanks for the help.

    
asked by anonymous 29.03.2016 / 22:44

1 answer

1
$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);


ftp_close($conn_id);

No HTML

<?php
    foreach ($list as $row)
     {
        echo"<tr>";
        echo "<td>www.site.com.br" . $row . "</td>" ;
        echo"</tr>";
     }  

?>

Now that's right, who needs it is there. @AdrianoLuz I was doing a foreach, but I do not know what I was doing wrong that was returning with error.

    
30.03.2016 / 16:32