Home > Article > Backend Development > php ftp function file upload
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);
?>