Hello I am having some trouble with some "force download" code. I have spent many days on google looking for a good tutorial / script but there appears to be issues with everyone of them that I try.
I came across a simple one that I got sort-of working, however the PDFs that it downloads error for some reason. The PDF when trying to open (in adobe reader) produces the following error:
Could not open '3GLG534WW.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).
My website with an example download link is: http://www.reese-test2.co.uk/3GLG534WWc.php - click on the green button
Does anyone know what I need to alter to get it to work? code below on my script (downloadSPECS.php) and underneath that the code on the actual link to the PDF
The script code (downloadSPECS.php) :
<?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('http://www.reese-test2.co.uk/Downloads/Specs' . $pdf);
?>
The code on the green button / PDF link:
<p><a href="http://www.reese-test2.co.uk/scripts/downloadSPECS.php/3GLG534WW.pdf" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('SpecDL','','images/specDLB.jpg',1)"><img src="images/specDL.jpg" alt="Download Spec Sheet" width="196" height="71" id="SpecDL" /></a></p>
<p> </p>