Skip to main content
Inspiring
November 10, 2009
Question

Download file from within CFWindow

  • November 10, 2009
  • 1 reply
  • 990 views

I have a CFwindow that I want the user to be able to click on a buttom to create a zip archive of some files. I have the window and the zipping part working correctly, and I am using cfheader and cfcontent to deliver the zipped file to the browser, yet when it tries to do the cfcontent part, it hangs the browser and never prompts to download.

Here is some sample code im doing for the cfcontent:

<cfif isDefined('form.zip_button')>
            <cfzip action="zip" file="#application.webroot#\_ziptemp\#session.username#.zip" filter="*.jpg"
            overwrite="yes" recurse="yes" source="#application.userroot#\#session.userfolder#" storepath="yes"></cfzip>
            <cfheader name="Content-disposition" value="inline; filename=#session.username#.zip">
            <cfcontent  file="#application.webroot#\_ziptemp\#session.username#.zip" type="application/x-zip-compressed" deletefile="yes">
     </cfif>

Anyone have any ideas how to pull this off?

Thanks

    This topic has been closed for replies.

    1 reply

    Known Participant
    November 10, 2009

    have you tried using attachment instead of inline in your cfheader?

    <cfheader name="Content-disposition" value="attachment; filename=#session.username#.zip">

    i have noticed if your filename has a space in it it will screw it up as well...

    AbinidiAuthor
    Inspiring
    November 11, 2009

    I actually figured it out today how to do it.

    I had to have inside  the CFwindow an Iframe that loaded the content that I wanted to have do the zipping and CFHEADER/CFCONTENT and it worked.

    cfwindow -- iframe -- source code

    As for the inline/attachment, either one will work as once the file is forced to the client browser, it will determine what/how to open it and proceed from there.

    Inspiring
    November 11, 2009

    cfwindow -- iframe -- source code

    BTW, I would guess the cfwindow alone did not work because it does not open a separate browser window. So you are limited to the content-type of the main page. An iframe is akin to using a separate window, where you can establish a different content-type.