function pdf_export_download in PDF Export 7
Apply the headers for PDF download.
1 string reference to 'pdf_export_download'
- pdf_export_menu in ./
pdf_export.module - Implements hook_menu().
File
- ./
pdf_export.module, line 257 - PDF Export module.
Code
function pdf_export_download($real_filename, $filename) {
$scheme = _pdf_export_get_scheme_wrapper();
// Cannot find the scheme, something must be broken.
if (empty($scheme)) {
drupal_not_found();
}
$pdf_uri = sprintf('%s/%s', $scheme
->getUri(), $real_filename);
$scheme
->setUri($pdf_uri);
$pdf_path = $scheme
->realpath();
if (!file_exists($pdf_path)) {
drupal_not_found();
}
// Serve file download.
drupal_add_http_header('Pragma', 'public');
drupal_add_http_header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
drupal_add_http_header('X-Content-Type-Options', 'nosniff');
drupal_add_http_header('Content-Type', 'application/pdf');
drupal_add_http_header('Content-Disposition', "attachment; filename={$filename};");
drupal_add_http_header('Content-Transfer-Encoding', 'binary');
drupal_add_http_header('Content-Length', filesize($pdf_path));
readfile($pdf_path);
$scheme
->unlink($scheme
->getUri());
drupal_exit();
}