PHP FTP - Browse Directories

Hi Chaps,

I’ve managed to view the contents of an FTP site and have upload files successfully.

I’m using the ftp_nlist/ftp_rawlist to build an array of the files in a given directory, but how can I browse through the directories (in a similar way to deault FTP / Windows)?

Cheers

You will want to look into the ftp_chdir command. It allows you to change your currently viewed dir.

Hi smftre, thanks for the link, I’ve got a couple more related questions.

  1. If I’m using ftp_nlist/ftp_rawlist to build an array of files/directories, how do I determine which are files and which are directories(to then apply ftp_chdir)
  2. Once I have file/directories seperated, how do I use ftp_chdir correctly (do I use a url parameter/$_POST form, etc)?

<?php
function ftp_isdir($connect_id,$dir)
{
if(ftp_chdir($connect_id,$dir))
{
ftp_cdup($connect_id);
return true;

} 
else 
{ 
    return false; 
} 

}
?>

as stated on: http://uk3.php.net/manual/en/function.ftp-rawlist.php

Thanks for the reply, I guess this function checks to see if the directory exists, if it does, it changes to the selected directory, otherwise it doesn’t(?). . . .how do I set this up in the correct way? If I have a list of directories, would I use a <a href> tag to e.g.: ‘move_dir.php?directory=“selected directory”’, then the code you gave me would be on ‘move_dir.php’?