I have found that for certain formats, for example, PDF, the simple code:
header("Content-type: application/x-download");
header("Content-Disposition: attachment; filename=$file_download_name;");
@readfile($file_server_path);
does not work, and produces corrupted files for all browsers on all platforms. During the downloads, I noticed that the browser was not receiving ahead of time the length of the file, which was somehow causing some formats to be corrupted.
e.g.: "Downloading file example.pdf: 347.2 KB of ?"
I solved the problem by adding more headers:
$download_size = filesize($file_server_path);
header("Content-type: application/x-download");
header("Content-Disposition: attachment; filename=$file_download_name;");
header("Accept-Ranges: bytes");
header("Content-Length: $download_size");
@readfile($file_server_path);
Somehow the files aren't corrupted when the browser knows how big they are from the start.
I hope that helps
Bookmarks