Forum Moderators: open
'Right Click and Choose Save As ' method for getting their PDF's
However today I purchased an ebook that gave me a login to a system that had a simple 'button' that allowed me to click on it and up popped the same download box.
I've taken a screen shot of it here: snip
Does anybody know how this is done or could direct me to a script?
[edited by: encyclo at 6:08 pm (utc) on Jan. 24, 2006]
[edit reason] no links to screenshots please [/edit]
[webmasterworld.com...]
[webmasterworld.com...] (msg#3)
Tapolyai, no it's not created on the fly, nothing that complicated, just a pdf we upload to a site that we woudl like users to be able to download just by clicking a download button rather than fart around with right click save as etc.
I did post a screen shot of exactly what it was doing but it's been removed , not quite sure why that is I guess somebody must have posted something nasty in a screen shot.
I will paste this in for anybody who does a search in the future on PDF and downloading via a button
What you need to do is "tell" the browser it's something else from the server side and munge up the content-type header - that is, give it a content-type you KNOW it can't possibly understand. A sample in perl:
## Store the filename in a variable:
$filename = 'yourfile.mov';
## open file and store in a variable (e.g., in memory)
open (FILE,"$filename");
## Not usually, but SOMETIMES, on some servers, you
## have to specify binary mode when reading the file.
## binmode FILE;
while (<FILE>) { $file .= $_; }
close (FILE);
## Can't remember why this must be one more byte than length!
$size = length( $file)+1;
## tell the browser it's an unknown type.
## this can be anything that is NOT a known
## type, ex "Content-type: blabla/debla";
print "content-type: bad/type\n"; # ONE return
print "Content-Length: $size\n"; # ONE return
# "filename" populates save box.
print "Content-Disposition: attachment; filename=$filename\n\n"; ## TWO returns flushes the content-type header and ...
print " $file"; ## deliver the goods.
This works for binary or ASCII data; pdf's, media, images, anything. When you munge the content header the browser's only option is to offer the requested file as a download. The above can be emulated in any server-side language. But I don't know what you can do in JS, never tried. :-)