Php web page ftp code
<? Php
$ Ftpserver = "127.0.0.1 ";
$ Ftpport = "21 ";
$ Ftpuser = "anonymous ";
$ Ftppassword = "";
If ($ _ POST)
{
$ Action = $ _ POST [action];
Switch ($ action)
{
Case "open ":
Case "change ":
$ Ftpserver =$ _ POST [ftpserver];
$ Ftpport = $ _ POST [ftpport];
$ Ftpuser = $ _ POST [ftpuser];
$ Ftppassword =$ _ POST [ftppassword];
$ Ftp = @ ftp_connect ($ ftpserver, $ ftpport );
If (! $ Ftp) {echo "connecting to the FTP server". $ ftpserver. "port". $ ftpport. "failed"; exit ;}
$ Rs = @ ftp_login ($ ftp, $ ftpuser, $ ftppassword );
If (! $ Rs) {echo "the user name or password is incorrect. An error occurred while connecting to the FTP server"; exit ;}
$ CurDir = $ _ POST [curDir];
If ($ curDir = "") $ curDir = "/";
If ($ curDir = "/")
{
$ ParentDir = "/";
} Else {
If (strrpos ($ curDir, "/") = 0)
{
$ ParentDir = "/";
} Else {
$ ParentDir = substr ($ curDir, 0, strrpos ($ curDir ,"/"));
}
}
$ Arr = ftp_rawlist ($ ftp, $ curDir );
If (count ($ arr)> 1)
{
Foreach ($ arr as $ val)
{
If ($ curDir = "/")
{
$ Val = "/". trim (strrchr ($ val ,""));
} Else {
$ Val = $ curDir. "/". trim (strrchr ($ val ,""));
}
$ File_size = ftp_size ($ ftp, $ val );
If ($ file_size =-1)
{// Directory
$ Dirlist [] = str_replace ("\", "/", $ val );
} Else {
$ Filelist [] = str_replace ("\", "/", $ val );
}
}
}
Break;
Case "close ":
Break;
}
}
Next let's take a look at the WEB page form.
?>