iEntry 10th Anniversary RSS Newsletter Advertising
Visit Twellow.com
Text: Decrease Font Size Increase Font Size | Print Print Article | Share: Delicious Digg StumbleUpon Post to Twitter Post to Facebook
CommentTuesday, June 1, 2004

Correct Content (document) Serving!

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]

News Tags: content, HTTP
About the author:
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!

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

Thanks

Publish A Comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
2 + 7 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
SEARCH
Popular WPN Business Resources












Subscribe to WebProNews


Send me relevant info