Usually just creating a link to the cfheader content page will push the 
download without changing the current page location. Basically this allows the 
calling page to be downloaded but you could modify it to however you want. 
Instead of using the application.cfc, just include it as your download link 
(<tag:download filename="./myPDF.pdf"/>

I created a custom tag once that you can include on any page:


In the application.cfc:

        <cffunction name="onRequestStart" access="public" returntype="string">
        <cfargument name="targetPage" required="yes">
                        <cfimport taglib="../CustomTags/" prefix="tag">
                        
                        <div>
                                <tag:download filename="#targetPage#"/>
                        </div>
</cffunction>

Custom tag:

<cfparam name="attributes.filename" default="">
<cfif thisTag.ExecutionMode is 'start'>
        <cfoutput>
        <a href="#attributes.filename#?download=true" target="_blank">DOWNLOAD 
THIS FILE</a>
        </cfoutput>
        <cfparam name="url.download" default="false">
        <cfif url.download eq true>
                <cfscript>
                         DL = createObject("component","com.site");
                         DL.download(attributes.filename);
                </cfscript>
        </cfif>
</cfif>
<cfif thisTag.ExecutionMode is 'end'></cfif>


In the component page:

        <cffunction name="download" access="remote">
                <cfargument name="filename" default="">
                <cfscript>
                filePath = ExpandPath(filename);
        </cfscript>
                        
                <cfheader name="Content-Disposition" value="attachment; 
filename=#getFileFromPath(filePath)#"> 
                
                <cfcontent file="#filePath#" type="text/plain"> 
        </cffunction>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:327146
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to