Php web page ftp code 4 download files

Source: Internet
Author: User

Php web page ftp code 4 download files

<? Php
$ 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 ;}
$ TargetDir = str_replace ("\", "/", stripslashes ($ _ POST [targetDir]);
$ Filename = substr (strrchr ($ _ POST [filelist], "/"), 1 );
Echo $ filename;
// Exit;
If (substr ($ targetDir, strlen ($ targetDir)-1) = "/")
{
$ Rs = @ ftp_get ($ ftp, $ targetDir. $ filename, $ _ POST [filelist], FTP_ASCII );
} Else {
$ Rs = @ ftp_get ($ ftp, $ targetDir. "/". $ filename, $ _ POST [filelist], FTP_ASCII );
}
If ($ rs)
{
If (substr ($ targetDir, strlen ($ targetDir)-1) = "/")
{
Echo "<script> alert ('file downloaded successfully, the path of the file on the local machine is [". $ targetDir. $ filename. "] '); window. close (); </script> ";
} Else {
Echo "<script> alert ('file downloaded successfully, the path of the file on the local machine is [". $ targetDir. "/". $ filename. "] '); window. close (); </script> ";
}
Exit; I am
} Else {
Echo "<script> alert ('file download failed. Check whether the target folder exists. The source file is [". $ _ POST [filelist]. "] '); window. close (); </script> ";
Exit;
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.