In php, how does one automatically upload files from an ftp server? The uploaded file is smaller than the original file.
Source: Internet
Author: User
How does php automatically download files from an ftp server without a pop-up file download box? Is the downloaded file smaller than the original one? & Lt ;? PHP $ filename = & quot;/www/767675.dat& quot; php_ftp_download ($ filename); & nbsp; functionp php implements file download from the ftp server. how does one enable automatic download without the pop-up file download box? Is the downloaded file smaller than the original one?
$ Filename = "/www/767675.dat ";
Php_ftp_download ($ filename );
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 );
Readfile ($ tmpfile );
Unlink ($ tmpfile); // delete a temporary file
Exit;
}
Unlink ($ tmpfile );
}
}
}
Ftp_quit ($ ftp );
}
?>
1. how does php automatically download files from an ftp server? The following download selection box is not displayed.
2. how to download and save the file and prompt that the download is successful, but the downloaded file is smaller than the original file?
------ Solution --------------------
In my opinion, this download prompt should not disappear, because this is a windows protection for system security. if you click a file, it will be automatically downloaded to the local device, isn't the computer very insecure?
Are the files you downloaded on two different system platforms? If yes, it will cause different sizes. It is also possible that the data reading is incomplete. you can download the data by using FTP and check whether the file is the same.
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.