& Lt ;? Php/*** function name php_ftp_download * function download file from ftp server * entry parameter * file name to be downloaded, including Path */functionphp_ftp_download ($ filename) {$ phpftp_host & quot; ftplocalhost & quot; // service...
/**
* Function name: php_ftp_download
* Function to download files from an ftp server
* Entry parameters
* Filename: the name of the file to be downloaded, including the path
*/
Function php_ftp_download ($ filename ){
$ Phpftp_host = "ftplocalhost"; // server address
$ Phpftp_port = 21; // server port
$ Phpftp_user = "name"; // User name
$ Phpftp_passwd = "passwrd"; // password
$ Ftp_path = dirname ($ filename). "/"; // Obtain the path
$ Select_file = basename ($ filename); // get the file name
$ Ftp = ftp_connect ($ phpftp_host, $ phpftp_port); // connect to the ftp server
If ($ ftp ){
If (ftp_login ($ ftp, $ phpftp_user, $ phpftp_passwd) {// login
If (@ ftp_chdir ($ ftp, $ ftp_path) {// enter the specified path
$ Tmpfile = tempnam (getcwd (). "/", "temp"); // create a unique temporary file
If (ftp_get ($ ftp, $ tmpfile, $ select_file, ftp_binary) {// download the specified file to a temporary file
Ftp_quit ($ ftp); // close the connection
Header ("content-type: application/octet-stream ");
Header ("content-disposition: attachment; filename =". $ select_file) // content-disposition: inline; indicates that files can be opened online!
Readfile ($ tmpfile );
Unlink ($ tmpfile); // delete a temporary file
Exit;
}
Unlink ($ tmpfile );
}
}
}
Ftp_quit ($ ftp );
}