Image link that downloads a pdf
Moderator: General Moderators
Image link that downloads a pdf
Hi I want to have a image link where people can click to download a pdf file. I would appreciate any sort of help.
Re: Image link that downloads a pdf
I think you need to look at basic HTML tutorials.
http://www.w3schools.com/htmL/html_images.asp
http://www.w3schools.com/htmL/html_links.asp
Some browsers open PDFs in the browser, if you're looking to force a download then you'll need to look into HTTP headers and the header() function... but if you're struggling to even make a linked image then I'd leave the force download stuff for now.
http://www.w3schools.com/htmL/html_images.asp
http://www.w3schools.com/htmL/html_links.asp
Some browsers open PDFs in the browser, if you're looking to force a download then you'll need to look into HTTP headers and the header() function... but if you're struggling to even make a linked image then I'd leave the force download stuff for now.
Re: Image link that downloads a pdf
I have no problem making a link. How can I download the pdf?
Re: Image link that downloads a pdf
See Example 1 in the header() documentation as I pointed out in the earlier post:
http://uk2.php.net/manual/en/function.header.php
http://uk2.php.net/manual/en/function.header.php
Re: Image link that downloads a pdf
don't understand how to use that.
Re: Image link that downloads a pdf
Link to a PHP page, in that PHP page have:
Obviously changing the filenames to match the one's you want. Easy. (that code is unedited from php.net).
Code: Select all
<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');
?>Re: Image link that downloads a pdf
Well, here you have to make yourself familiar with HTTP, not with PHP, because header() function sends HTTP headers. However, I assume you are looking for quick solution (read about the HTTP protocol as soon as you can), so I will tell you, that you have to send a Content-type header (usualy application/ocstream to force download instead of opening with the configured plugin; this is like saying "unknown type, so you cannot open it right now, you have to downloading first) and Content-disposition: attachment. I'm writing this on prima vista, I didn't check the exact spelling, but I believe that you can find this with one search in Google. So:thoque wrote:don't understand how to use that.
Code: Select all
header('Content-type: application/ocstream');
header('Content-Disposition: attachment; filename="your-pdf-file.pdf"');
readfile('your-pdf-file.pdf');Re: Image link that downloads a pdf
Why not use the proper mime-type like the php.net documentation does? I'm not trying to sound coy, I'm genuinely intrigued
Re: Image link that downloads a pdf
It's all about the browser. I do not remember exactly, as this was 2 or 3 years ago when I had problems with downloading the file... as far as I remember some of the major browsers was ignoring the content-disposition header. Just try your code with IE 6, FF and Opera... If it works with all of them, than I'm just wrong. But I have the habit to use octet-stream content-type since the time I was implementing the downloading of files for the first timemikemike wrote:Why not use the proper mime-type like the php.net documentation does? I'm not trying to sound coy, I'm genuinely intrigued
P.S. it seems to be an IE problem: Microsoft Support on Content-disposition
Somewhere at Internet... wrote:To be on the safe side and ensure consistent behavior in all browsers, it's usually better to use both:
Content-Type: application/octet-stream
Content-Disposition: attachment;filename=\"My Text File.txt\"