Home  >  Article  >  Backend Development  >  php ftp function file upload

php ftp function file upload

高洛峰
高洛峰Original
2016-11-29 15:09:251081browse

Many times we don’t use the php ftp function to upload files, but we will use the ftp function when using more advanced WEB applications. For example, I want to transfer the uploaded pictures to server B and save the data to server A. Normally The php file upload example cannot be used, but it can be easily done using the ftp function. The code is as follows:

// Define variables

$local_file = 'local.zip';

$server_file = ' server.zip';

//Connect to FTP server

$conn_id = ftp_connect($ftp_server);

//Verify login server

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

/ / Download file

if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {

echo "Download $local_file file successfully";

} else {//Open source code phpfensi.com

echo "Download Failure ";

}

//Close ftp connection

ftp_close($conn_id);

?>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn