note 35538 deleted from function.header by kennyt
| From: | kennyt@php.net | Date: | Sun, 18 Jul 2004 18:08:23 +0000 |
| Subject: | note 35538 deleted from function.header by kennyt | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73563@lists.php.net to get a copy of this message | ||
Note Submitter: Marquinhos
----
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 :)