Hi,

im working on a web based ftp client, and i am at a loss for ideas, in the end i want a screen full of icons for each file on the ftp server but using

ftp_nlist ()

all im able to get is a list of things in an array...

Im wondering how i can arrange and possibly format each element of the array (because ftp_nlist outputs an array)...

thanks

ps im thinking a while or for loop but dont know how to implement on an array...

    ftp_nlist RETURNS an array, it does not output an array you must be doing this:

    echo ftp_nlist();

    do this instead:

    $files = ftp_nlist();
    
    foreach($files as $file)
    {
      echo "File: ". $file ."<br />";
    }
    

    That's a start you can format that anyway you want and it will do that for every file entry. you could try ftp_rawlist() as well, it gives you more information

      thanks heaps, the only thing is how does it work, i feel dirty usingcode that i dont know what it does (I speka da english goodly!) - i mean what is $file??? \

      thanks!

        davo666 wrote:

        what is $file???

        in the example ShawnK posted, the $file is simply a pointer to each piece of the array is the "foreach" loops travels through each iteration...

        $files = ftp_nlist(); 
        
        foreach($files as $file) 
        { 
          echo "File: ". $file ."<br />"; 
        } 
        

        the "foreach" loop will move from the beginning of the array to the end piece by piece, taking the piece as $file. This way, your code within the loop can operate individuall on $file and pull the information out of it. Basically, it lets you take the array of items you can create, and pull them out into a list.

        you could add in table tags or link text etc. within the loop for more formatting options.

        that probably didnt make much sense so if you have more questions just ask and let me try to clarify how i interpret it in my strange twisted mind...😉

        even better, stop by over here...
        http://www.php.net/manual/en/control-structures.foreach.php

        good luck! 🙂

          explained:

          $files = ftp_nlist(); //assign array of names into a local variable $files
          
          /*for every file within the array $files we assign it, for one iteration, to the variable $file, output it and add a line break*/
          foreach($files as $file) 
          {
            echo "File: ". $file ."<br />";
          } 
          

            yer, scroupulous, thats the kind of remember-me 2 liner i was looking for - thanks,

            but- ive been playing with foreachs now, and i can only create a one line table, like thats it i cant make table like

            $files $files files

            files files files

            files files files

            files files files

            • how do you do it???

              he's something going along with your example, and my code i showed you earlier:

              $files = ftp_nlist(); // this is an array of files
              
              echo "<table>";
              
              foreach($files as $file) 
              { 
                echo "<tr><td>". $file ."</td></tr>";
              }
              
              echo "</table>";
              
                Write a Reply...