How can the header function in PHP be used to trigger a file download, such as a .zip file, that is stored on the server?
To trigger a file download using the header function in PHP, you need to set the appropriate headers to indicate that the content being sent is a file attachment and specify the file type and name. You also need to read the file content and output it to the browser. This can be achieved by using the readfile function in combination with the header function.
<?php
$file = 'path/to/your/file.zip';
header('Content-Description: File Transfer');
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
?>