Thread: Force Downloads
View Single Post
Old 10-15-2004, 12:58 PM   #20 (permalink)
br00n
Upright
 
[CFMX] forcing file download

Hi, Christian Cantrell posted this on this blog. (http://www.markme.com/cantrell/archives/002658.cfm)
Very handy.

This could be from a query or pretty much any query type source...

<cffile action="readbinary" file="/home/cantrell/Pictures/Corrs2.jpg" variable="pic"/>

This 'could' be reduced...why not experiment?

<cfscript>
context = getPageContext();
context.setFlushOutput(false);
response = context.getResponse().getResponse();
out = response.getOutputStream();
response.setContentType("image/jpeg");
response.setContentLength(arrayLen(pic));
out.write(pic);
out.flush();
out.close();
</cfscript>

It just takes some minor changes to change the content disposition and have the file 'download' to the client.

br00n

Last edited by br00n; 10-15-2004 at 01:02 PM.. Reason: taggined the thread.
br00n is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76