Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-09-04 17:02:49

claywso
Member
From: Durham, NC USA
Registered: 2004-12-20
Posts: 57
Website

Open File Download in Browser

I realize this might not be a textpattern issue, but you all always know the answers!

Client would like to make sure that all PDFs open IN the browser. Right now, though, file download links (pdfs) prompt a download.

thanks for your help.

Offline

#2 2010-09-04 20:42:28

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,477

Re: Open File Download in Browser

The last decision what happen with a PDF has the visitors of the website. The owner of the site should not could decide what happens in the visitor’s computer. I hope that stay so.

Offline

#3 2010-09-04 21:11:20

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,000
Website GitHub

Re: Open File Download in Browser

I beg to differ: txp does indeed override the user’s choice in this case and downloads the PDF even if the user wishes to view it in the browser. If you do not need to count downloads, you can simply link directly to the pdf file in your /files/ folder (i.e. not using txp:file_download), for example.

See this thread for more thoughts on a potential workaround.


TXP Builders – finely-crafted code, design and txp

Offline

#4 2010-09-04 21:39:21

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,477

Re: Open File Download in Browser

That depends on some factors. In Safari Mac, for example, I can use CTRL-Click for download or I can install Thinker Tool for changing the default in Safari or I can change it in the terminal …

Offline

#5 2010-09-05 09:45:34

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,000
Website GitHub

Re: Open File Download in Browser

I understand that you can change your preferred browser settings as a user or ctrl-click to download rather than display in a browser (and I agree with the sentiment that it should be the user’s choice), but I didn’t know that you can make files provided via <txp:file_download_link /> show in the browser. My understanding is that txp forces such files to download even when they could be displayed in the browser.


TXP Builders – finely-crafted code, design and txp

Offline

#6 2010-09-05 10:31:44

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Open File Download in Browser

jakob wrote:

My understanding is that txp forces such files to download even when they could be displayed in the browser.

Yes and no. TXP does invoke standard file transfer, but it’s nothing more than header communication between server and browser which makes sure that the visitor doesn’t try to open the file in the browser. What browser really does with the feeded file, is up to the browser.

Last edited by Gocom (2010-09-05 10:34:08)

Offline

#7 2010-09-06 17:24:08

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Open File Download in Browser

Textpattern serves the files with content-type “application/octet-stream” regardless of what the actual content of the file is. That’s what causes the browser to ask you what you want to do with the PDF file instead of directly showing the PDF, which is what would’ve happened if the content-type “application/pdf” were used for PDF files. I suspect most (all?) modern browsers behave like this.

Not all files that have a name that ends with “.pdf” are PDF files, so if you want to change this behaviour you’ll have to use something like the finfo_file() function in PHP to detect the mime type based on the content of the file. It might be a nice idea to offer this as a preference in TXP: if the extension and the content of the file match, allow it to be served with a matching content type otherwise revert to application/octet-stream.

Offline

Board footer

Powered by FluxBB