Sometimes you prefer to display a file (say, a PDF document) inline rather than serving it for download. Certainly, you could use its raw URL and bypass all Textpattern processing, but you often need to automate the process, based on the file category or something else.
In txp 4.7.2 this becomes rather straightforward, you need just a tiny plugin configurable via a form. Install and activate it, then create a file category, say inline-pdf
. Now create a file type form named file_download_header
:
<txp:if_category category='<txp:file_download_category />' name="inline-pdf">
<txp:header name="Content-Disposition" value="inline" />
<txp:header name="Content-Type" value="application/pdf" />
</txp:if_category>
Assign inline-pdf
category to some file. Now, clicking on its download link should display it in capable browsers rather than opening a download dialog. And if you need to display it inline, this should do:
<object data="<txp:file_download_link id="54" />">
<p><a href="<txp:file_download_link id="54" />">Download PDF</a></p>
</object>
Let’s test it:
File(s)
- File: etc_output_file_v0.1.txt [1.89 kB] (736 downloads, ~11 per month)