What are best practices for handling headers and output when downloading zip files in PHP?

When downloading zip files in PHP, it is important to set the appropriate headers to ensure the file is downloaded correctly. This includes setting the content type to 'application/zip', specifying the file name, and sending the correct content length. Additionally, it is good practice to output the file contents using readfile() to handle large files efficiently.

<?php
// Set headers
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="example.zip"');
header('Content-Length: ' . filesize('example.zip'));

// Output file
readfile('example.zip');