5 Replies Latest reply on Nov 8, 2007 5:32 AM by ToBeNamedLater

    click link and download file

      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

        • 1. Re: click link and download file
          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
          <cfheader name="content-disposition" value="attachment; filename = #trim(filename)#">
          <cfcontent type="text/xml;">
          <cffile action="READ" file="#absolutefilepath#" variable="content" charset="iso-8859-1">
          • 2. Re: click link and download file
            Duke Snyder
            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.
            • 3. Re: click link and download file
              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.
              • 4. Re: click link and download file
                Tiono Level 1
                wow, thanks man. I didn't know about that quote things :D
                so far never use filename with spaces hehehe.
                • 5. Re: click link and download file
                  ToBeNamedLater Level 1
                  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.