Jump to content

my ftp browser/file displayer


yayo

Recommended Posts

Hey I've roughly written a php ftp browser (file displayer) and I cant seen to get around the problem how I would navigate through the folders, 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.
I use a $_GET to tell the script what folder to look through but I want to be able to navigate solely through the hyperlinks
Here is my code so far:

<?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) I think ive explained it the best I can this is my first post so any help would be appreciated

Link to comment
Share on other sites

The script works for me with some little corrections.

if (isset($_GET['page']))
   {
   $path = urlencode($_GET['page']);
   }
   else
   {
   $path = '';
   }

Example1 (whitout get parameter)

URL:10.10.1.5:90/pdo/freaks.php

 

Example2

URL:10.10.1.5:90/pdo/freaks.php?page=6.Years.in.Love.2008

 

post-124152-0-28693400-1402184518_thumb.png

post-124152-0-64251900-1402184528_thumb.png

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.