All you have to do is set the Content-Dispositiontitle attachmentto get the Save As dialog. Here is an example PHP for beginners:
<?php
header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename="foo.pdf"');
readfile('/path/to/foo.pdf');
?>
You cannot and do not want to do this with Javascript.
Important Note: Due to a poor function in MSIE, the default file name in the Save As dialog box will not be displayed from the header Content-Disposition, it will instead be the last part of the path in the request URL. To get around this, add the PDF file name to the link, for example. http://example.com/pdf/foo.pdf. You can even use it in PHP to read in a specified PDF file with a path. Here is a basic example pdf.php:
<?php
$file_name = $_SERVER['PATH_INFO'];
$file = '/path/to/pdf/files' . $file_name;
if (file_exists($file)) {
header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename="' . basename($file_name) . '"');
header('Content-Length: ' . filesize($file));
readfile($file);
} else {
header('HTTP/1.1 404 Not Found');
}
?>
, MultiViews, /pdf/ PHP , , RewriteRule /pdf/ /pdf.php/.
, , PDF PDF.
, :
<?php
$file_name = $_SERVER['PATH_INFO'];
$file = '/path/to/all/files' . $file_name;
if (file_exists($file)) {
header('Content-Type: ' . mime_content_type($file_name));
header('Content-Disposition: attachment;filename="' . basename($file_name) . '"');
header('Content-Length: ' . filesize($file));
readfile($file);
} else {
header('HTTP/1.1 404 Not Found');
}
?>
files.php , PHP-, , , http://example.com/files/foo.pdf, http://example.com/files/bar.zip ..
, .