• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

click link and download file

Guest
Nov 02, 2007 Nov 02, 2007

Copy link to clipboard

Copied

Hi ,

I am creating xml file from query and then read xml file as pdf using cf document.
So I have my list in the website as xml file and pdfs So if click on xml it should ask me for download/save as and same thing for pdf. How can I do that. I know cfcontent but it doesn't work

TOPICS
Advanced techniques

Views

3.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 04, 2007 Nov 04, 2007

Copy link to clipboard

Copied

You can try below code for your XML file.

<cfheader name="content-disposition" value="attachment; filename = #trim(filename)#">
<cfcontent type="text/xml; charset=utf-8" file="#absolutefilepath#">


If it doesn't work, then try below one :D
<cfoutput>
<cfheader name="content-disposition" value="attachment; filename = #trim(filename)#">
<cfcontent type="text/xml;">
<cffile action="READ" file="#absolutefilepath#" variable="content" charset="iso-8859-1">
#trim(content)#
</cfoutput>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 06, 2007 Nov 06, 2007

Copy link to clipboard

Copied

here is how I have always done this. I create a file called download.cfm. In that file I simply put this code

<cfsetting enablecfoutputonly="yes">
<cfheader name="Content-disposition" value="attachment; filename=""#Url.FileName#""">
<cfcontent type = "foo/bar" file = "/path_to_the_file/#Url.FileName#">

Now I pass the FileName through the Url and it WILL ask if you want to open or download the file. We accomplish this by making up an eronious file type.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 07, 2007 Nov 07, 2007

Copy link to clipboard

Copied

Just to call attention to something for Tiono:

Note the quotes around the filename= parameter in Duke Snyder's code:

<cfheader name="Content-disposition" value="attachment; filename=""#Url.FileName#""">

(although I make mine easier to read by mixing single and double quotes as in:

<cfheader name="Content-disposition" value='attachment; filename="#Url.FileName#"'>

if you don't surround the file name with quotes, you'll have trouble downloading files with spaces in the name. And the quotes need to be double quotes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 07, 2007 Nov 07, 2007

Copy link to clipboard

Copied

wow, thanks man. I didn't know about that quote things :D
so far never use filename with spaces hehehe.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 08, 2007 Nov 08, 2007

Copy link to clipboard

Copied

LATEST
If you have total control over your own system, you can disallow spaces, but if you have to allow "the public" to upload files, you have to be able to handle it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation