Forum Moderators: phranque

Message Too Old, No Replies

Create download

         

goldengob

8:20 pm on Dec 9, 2004 (gmt 0)

10+ Year Member



Please help!

I'm pretty new at this so please bare with me.

What I'm trying to do is to create a download link on one of my web pages so that when someone clicks on it they can download my ebook. I just can't seem to find how to do it.

Can anyone help?

Thanks in advance!

rocknbil

2:19 am on Dec 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you click a link, the browser generally sniffs the file type and determines how to manage it. This **used** to be by simply reading the extension (in this case .pdf) but even if you change the extension it may still recognize the content-type as pdf.

What you have to do is "munge" the content type being sent to the browser, basically creating a content-type the browser won't recognize. Generally this is done with a with a dynamic server-side language.

Using my favorite, perl,

open <FILE,"$pdf_file">;
$file = <FILE>;
close (<FILE>);

Now my entire pdf is stored in $file. Normally, the server sends the content-type of application/pdf for this file, and if it doesn't the browser might figure it out, but we need to trick the browser into forcing a download:

print "content-type:bad/type\n\n";
#or
#print "content-type:any/unrecognized_type\n\n";
print "$file";
exit 0;

The unrecognized MIME type forces the browser to download the file, as it doesn't recognize the type.

There's more to the story, such as content-disposition and how to populate the file dialogue box with the file name, but that's the gist.

If you're not up to this, the simplest solution is a clear set of instructions: "Right-click THIS LINK and select 'Save Target As' from the context menu to download my ebook. Macintosh users, hold down your Apple key before clicking the link."