17 Replies Latest reply: Apr 26, 2013 12:30 PM by Acainion RSS

    How do I force a file download from a folder above the root?

    scooterboogle Community Member

      I am new to ColdFusion and need some help. I set up a virtual folder on my website and then mapped in the CF9 admin panel to a "Docs" folder above my root, where I would like to store sensitive documents. CF tags are enabled.

       

      I know that my mapping is set up correctly, because when I set up a cfm page with the following code, I can successfully download the file:

      <cfheader name="Content-Disposition" value="attachment; filename=Calendar.pdf">
      <cfcontent type="application/pdf file=/Docs/Calendar.pdf">

       

      But what I need is to create one cfm age that will be able to handle downloads of multiple files types and names from the folder above my root.

       

      I then found Duke Snyder's solution on an older forum for the "click link and download file" question where he suggests making a "download.cfm" page with the following code:  I did this, and named the file "download.cfm"

       

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

       

      Then Duke suggests: "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."

       

      I then set up a password-protected page on the site that lists the titles of a number of documents, with links to the virtual folder, where they can be downloaded.  One of the links, which goes to "Calendar.pdf" I constructed as: "download.cfm?FileName=Calendar.pdf"  When I click on the link, I get the popup box that says "Do you want to open or save this file?  With the name listed as: "download.cfm?Filename=Calendar_pdf"

       

      When I click "Save", I get the message: "Internet Explorer cannot download download.cfm from www.... Internet Explorer was not able to open this Internet site.  The requested site is either unavailable or cannot be found. Please try again later.

       

      I must have constructed the link incorrectly. Any ideas?  Thanks in advance for your help.