Results 1 to 2 of 2

Thread: my ftp browser

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2013
    Posts
    4

    my ftp browser

    hey ive roughly written a php ftp browser (file displayer) and i cant seen to get around how i would navigate through the urls, im fairly new to php and haven't had much experience just wondering that some methods could be for keeping track of what directory i am in and how to navigate up and down through the files and folders, I'm looking for ideas not necessarily solutions.
    Here is my code so far:
    Code:
    <?php
    ini_set('upload_max_filesize', '10M');
    ini_set('post_max_size', '10M');
    ini_set('max_input_time', 300);
    ini_set('max_execution_time', 300);
    
    $host = "";
    $user = "";
    $password = "";
    
    $ftp_connection = ftp_connect($host);
    
    ftp_login($ftp_connection, $user, $password);
    
    if (isset($_GET['page']))
       {
       $path = "/" . $_GET['page'];
       } 
       else
       {
       $path = "/";
       }
    
    $file_list = ftp_nlist($ftp_connection, $path);
    echo "<table border=1><tr><td>File Name</td><td>File Size</td><tr>";
     for($index = 0; $index < sizeof($file_list); $index++)
       { 
       echo "<tr>";
       $file_size = ftp_size($ftp_connection, $file_list[$index]);
       $file_name = $file_list[$index];
       if ($file_size == -1)
          {
          echo "<td><a href=browse.php?page=" . $path . $file_name . ">" . $file_name . "</a></td><td><b>Folder</b></td></tr>";
          }
          else
          {
          echo "<td>" . $file_name . "</td><td>" . $file_size . "</td></tr>";
          }
    
       }
    
    
    ftp_close($ftp_connection);
    I'm fairly tired so I will sleep on the problem and check back in the morning (it may just be because I'm tired I cant think of a solution)
    any tips on general coding practices would be nice too

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: my ftp browser

    I am not too familiar with the ftp functions of PHP, but if you want your script to know what folder or file you are on, just keep the location in a query string.

    yoursite.com/ftp.php?f=home/htdocs/my/folder/file.doc

    Then in that code above, load that $_GET['f'] contents.
    My usual boring signature: Something

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width