Quantcast

Correct Content (document) Serving!

Get the WebProNews Newsletter:
[ Business]

I tend to do a lot of document serving in my daily routines, by this I mean serving documents from the server to the visitor (end-user) in formats other then HTML..

Such as PDF, MS Word, MS Excel, etc..

Now, the easiest and fastest way to achieve this is to use CFCONTENT.

You simply use CFCONTENT to serve the file (using an MS WORD AS AN EXAMPLE) as follows:

<cfcontent type="application/msword" file="#ExpandPath(".")#\Tutorial_#URL.TutorialID#.doc" deletefile="yes">

Now the only problem is that doing this will make the download be the name of your ColdFusion template, and not that of the file you want named (such as: “tutorial_1.doc”.

So how do we get around this? Using CFHEADER as follows:

<cfheader name="content-disposition" value="attachment;filename=Tutorial_#URL.TutorialID#.doc">

This will ensure that the downloaded file will be called what YOU want it to be called! :)

Here’s how to use it:

<!--- all your processing here to create the file you want to load (or load one with CFFILE if it already exists) --->

<!--- Now trick the browser and name the file whatever you want --->
<cfheader name="content-disposition" value="attachment;filename=Tutorial_#URL.TutorialID#.doc">

<!--- now serve the content --->
<cfcontent type="application/msword" file="#ExpandPath(".")#\Tutorial_#URL.TutorialID#.doc" deletefile="yes">

That’s it.. you’re done! :)

EasyCFM.Com introduces at least three new tutorials each week, written by the webmaster (Pablo Varando) and also from individual people who post their own tutorials for visitors to learn from. For more information please visit: http://www.easycfm.com [EasyCFM is Hosted by Colony One On-Line - http://www.colony1.net]

Correct Content (document) Serving!
About Pablo Varando
EasyCFM.Com introduces at least three new tutorials each week, written by the webmaster (Pablo Varando) and also from individual people who post their own tutorials for visitors to learn from. For more information please visit: http://www.easycfm.com [EasyCFM is Hosted by Colony One On-Line - http://www.colony1.net] WebProNews Writer
Top Rated White Papers and Resources
  • Guest

    how can you upload more than one file at a time using your example?

    Thanks