How can the Content-Length Header in PHP affect file downloads?
The Content-Length header in PHP can affect file downloads by specifying the size of the file being downloaded. If this header is not set correctly, it can cause issues such as incomplete downloads or slow performance. To ensure proper file downloads, make sure to set the Content-Length header to the actual size of the file being downloaded.
$file = 'example.zip';
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;