How can the issue of a corrupted file when opening a zip file transferred via FTP in PHP be resolved?

The issue of a corrupted file when opening a zip file transferred via FTP in PHP can be resolved by ensuring that the file is transferred in binary mode. This can be achieved by setting the FTP transfer mode to FTP_BINARY before downloading the file.

// Connect to FTP server
$ftp = ftp_connect('ftp.example.com');
ftp_login($ftp, 'username', 'password');

// Set transfer mode to binary
ftp_pasv($ftp, true);
ftp_set_option($ftp, FTP_BINARY, true);

// Download the zip file
ftp_get($ftp, 'local_file.zip', 'remote_file.zip', FTP_BINARY);

// Close FTP connection
ftp_close($ftp);