As the builtin browser of my ebook-reader (Sony PRS-T1) is quite stupid and wants to open .epub files as text-files instead of downloading them, I tried to force the browser to download the .epub files with this .htaccess file:
<FilesMatch "\.(?i:epub)$">
ForceType application/octet-stream
Header add Content-Disposition "attachment"
</FilesMatch>
However, this causes an internal server error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
When I leave out Header add Content-Disposition "attachment"
there is no error - however, the browser wouldn't download the file :(
Am I doing something wrong? Where does the Internal Server error come from?
[EDIT 2013-04-11]
I just earned the "popular question-badge" for this thread, which reminded me of adding some information.
I finally managed to force a download on Sony's PRS-T1 browser with the following php-function
function startDownload($path, $mimeType) {
if(!file_exists($path)) {
// File doesn't exist, output error
exit('file not found');
} else {
$size = filesize($path);
$file = basename($path);
// Set headers
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"$file\"");
header("Content-Type: $mimeType");
header("Content-Transfer-Encoding: binary");
header("Content-Length: $size");
// Read the file from disk
readfile($path);
}
exit();
}
Hope that helps somebody one day.