pdf download

Started by Sir Osis of Liver, July 15, 2022, 12:51:14 PM

Previous topic - Next topic

Sir Osis of Liver

Is there any way to make a pdf file download instead of open in browser?
"The best laid schemes o' mice an' men / Gang aft a-gley." - Robert Burns

Arantor

The attachment code tells the browser to take it as a download; the browser chooses to ignore this.

The only way you might get somewhere is if the code is changed to lie about the content but 1) browsers might still ignore it and 2) malware checkers might not like it much either.

Sir Osis of Liver

They're not attachments, there are two buttons, first one links to pdf and allows users to read online, browser opens it.  Second one is for direct download, but pdfs are zipped, which prevents browser from opening it, but requires user to unzip it, which may be problematic for the unwashed, especially on mobile.

"The best laid schemes o' mice an' men / Gang aft a-gley." - Robert Burns

Arantor

OK, so let's pretend for a minute that I'm *not* a mindreader.

Are they real buttons attached to a form or just things that look like buttons but using a regular link?

Are you just linking to the files on the server in a folder somewhere?

Sir Osis of Liver

https://ebook-mecca.com/index.php?topic=405.msg405#msg405

As you can see, READ ONLINE links to pdf, PDF links to zip of same file.

"The best laid schemes o' mice an' men / Gang aft a-gley." - Robert Burns

Arantor

In each of the folders that has a .pdf file you want to download, try adding an .htaccess file with the following:

<FilesMatch "\.pdf$">
   ForceType application/octet-stream
   Header set Content-Disposition attachment
</FilesMatch>

Note that this won't work if you want to somehow put them in the same folder as the read-online version.

Sir Osis of Liver

Will try that.  The files are currently in different subdirectories.  The read online pdfs are all in one, the zips are in 60 subdirs (by category).  I have a script I can use to change file extensions from .zip to .pdf, but haven't figured out how to apply it recursively to subdirs, so I'd have to run it 60 times (and upload the .htaccess 60 times).
"The best laid schemes o' mice an' men / Gang aft a-gley." - Robert Burns

Kindred

Changing the extension does not change the file type!!   If those are actually zipped pdfs, then changing the extension to .pdf from .zip would cause all sorts of troubles
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

Yup, because what is happening here is Apache will *think* the file is a PDF (because it won't actually check against the file content), serve it up with the application/pdf MIME type and virus scanners will absolutely freak out when they see a file that claims to be application/pdf but is in fact not.

As a clue: the first 3 bytes of a PDF file literally spell 'PDF'; the first 2 bytes of a zip file spell 'PK' after the guy who invented the format. Renaming it doesn't rewrite its content.

Sir Osis of Liver

Didn't think of that.  The .htaccess works, but would require replacing all the zips with the original pdfs.  We're setting up a separate support forum linked from the booksite (which is no longer a forum), will have to include guidance for handling various file types.  Anyway, thanks.
"The best laid schemes o' mice an' men / Gang aft a-gley." - Robert Burns

Sir Osis of Liver

Any idea why the .htaccess worked yesterday, tonight it doesn't?  Browser loads pdf with or without.
"The best laid schemes o' mice an' men / Gang aft a-gley." - Robert Burns

Sir Osis of Liver


<FilesMatch "\.pdf$">
   ForceType application/octet-stream
   Header set Content-Disposition attachment
</FilesMatch>


Doesn't work.

HTML5 'download' attribute doesn't work (not cross-origin problem, file in same directory).

Stumped. >:(
"The best laid schemes o' mice an' men / Gang aft a-gley." - Robert Burns

Advertisement: