|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
PHP FTP functions
I am writing a script which should connect to an FTP server, state the current directory in a breadcrumb type manner, list the current directory and each list item should be a link (to either list the subdirectory or download a file). From examining the PHP FTP functions I have managed to write the following simple script:
<PHP> <html> <head> <title>Server Name</title> <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Expires" content="-1"> </head> <body> <? $ftp_server="127.0.0.1"; $ftp_user_name="user"; $ftp_user_pass="pass"; // set up basic connection $conn_id = ftp_connect($ftp_server); $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // check connection if ((!$conn_id) || (!$login_result)) { echo("Cannot connect to Server Name"); } // get contents of the root directory $contents = ftp_nlist($conn_id, "/"); echo "<p>Server Name ", ftp_pwd($conn_id), "</p>"; // print each entry echo "<p>"; foreach ($contents as $entry) { echo $entry, "<br />"; } echo "</p>"; // close connection ftp_quit($conn); ?> </body> </html> </PHP> As you can see all this does is list the contents of the default directory and also state the current directory. I don't have a clue about how to make the list items into links. One refinement I'd like to be able to make would be to only display certain file types eg. It would only list directorie s or .JPEG files. However if someone could even just help me with the first part I would be greatful. I read the Devshed PHP FTP articles but didn't really quite understand them (the uploading etc. just got in the way and confused me i think) |
|
#2
|
||||
|
||||
|
If you're just listing out files in a directory, you might consider using PHP's file system functions instead of FTP...
http://us3.php.net/manual/en/ref.filesystem.php |
|
#3
|
|||
|
|||
|
I eventually plan to allow uploads to the FTP server and also have a login etc. which will track how much people are downloading uploading etc.
|
![]() |
| Viewing: Dev Shed Forums > System Administration > FTP Help > PHP FTP functions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|