February 24, 201016 yr I'm trying to find a way so when a user clicks on a link to pdf file it doesn't open but triggers the download action in the browser from what I've read I need to add an extra http header but I'm not too sure where this would be added or is there another way thanks
February 24, 201016 yr http://elouai.com/force-download.php Try googling next time as there are many easily found scripts available.
February 24, 201016 yr Author http://elouai.com/force-download.php Try googling next time as there are many easily found scripts available. Yes did try googling sorry wasn't sure what to search for is there a solution without php ?
February 25, 201016 yr Author I ended up using php in the end here's the code I used if its useful for anyone I put the pdf in the same folder as the php and then added the name of the php file before the pdf in the link example href="forms/file.php/file.pdf" <?php $pdf = substr($_SERVER['PATH_INFO'], 1); if(preg_match('/^[a-zA-Z0-9_\-]+.pdf$/', $pdf) == 0) { print "Illegal name: $pdf"; return; } header('Content-type: application/pdf'); header('Content-disposition: Attachment; filename=' . $pdf); readfile('path_to_pdfs' . $pdf); ?>
Create an account or sign in to comment