Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript automatic pdf download Reply To: automatic pdf download

#249928
Shikkediel
Participant

This one’s handy to force a download dialogue and not open the file:

https://css-tricks.com/snippets/htaccess/force-files-to-download-not-open-in-browser/

Beverley’s posted the exact terms to find the solution but let me just add what I’ve been using:

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="anyname.pdf"');
header('Expires: 0');
header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');

readfile('path/correctname.pdf');