Do you work with datasheets regularly ? Always getting .pdf files open in your browser and having to wait EONs for them to download/display ? Well here is a resolve for that most frustrating of problems with Adobe's "Handy file intercept" feature. Use this script to FORCE the browser to download the file rather than display it inline.
Browser Forced Download of Adobe Acrobat .PDF Files.
// html file with links to either display or download the .pdf file.
<a href="pdf.php?pdfile=File-name-here">Download File</a><br>
<a href="data/File-name-here.pdf">View File</a><br>
/* The following code assumes that the files are located in a folder
called "data" and all files are .pdf. I havent tested it with files that
have spaces in the name, so i dont know if it works. But it does work
fine with files using _ and - in the names. */
// Get the file size of the selected file (for convenience so you know how
// long you have to wait...
$len = filesize('data/'.$pdfile.'.pdf');
// Declare File Type...
header('Content-type: application/pdf');
// Name the file. Cound just call it download.pdf or other using this.
header('Content-Disposition: attachment; filename="'.$pdfile.'.pdf"');
// declare Files Size here (for the sake pf peoples sanity, please add this
header('Content-Length: '.$len);
// Path to original file to be read and sent to browser.
readfile('data/'.$pdfile.'.pdf');
/* You could of course modify this to work with other filetypes, or just remove the filetype totally, its up to you.
Please make sure you leave in the file size bit so people dont go insane
waiting for a file of undetermined time, tearing their hair out...
*/
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.