Skip to main content
Participating Frequently
April 8, 2007
Question

How does one download with CF?

  • April 8, 2007
  • 5 replies
  • 827 views
What tags do you use in your CF page to download a file (any file...video, audio, etc) from the CF server to your computer's hard drive? It should just take a couple of lines of code if I'm not mistaken. I know that "cffile" only uploads a file to the server.
This topic has been closed for replies.

5 replies

April 10, 2007
OR:

<cflocation url="ftp://username:password@domain.com/the_file.extension" addtoken = "no">

Just a thought ;)

HTH
BKBK
Community Expert
Community Expert
April 10, 2007
I'm trying to download a windows media audi file and it just seems to open the file in the web browser and not save it on the machine. It does this with other types of files also. What if I want to download the audio file from the server and save it to the hard drive of the computer. Here's the code I'm using:

<cfheader name="content-disposition" value="attachment; filename=1.mpeg">
<cfcontent type="audio/mpeg" file="C:\CFusionMX7\wwwroot\1.mpeg">


The extension .mpeg usually goes with the MIME type video/mpeg. The extension that usually goes with audio/mpeg is .mp3. Also, have a think about what Ian99 said.

Inspiring
April 10, 2007
as long as you use it's real content type, it will open up in whatever the default setting is for that file type ( especially file types that have browser plugins or hooks) ... i.e. an MPEG file is going to open up in an audio player unless there is no audio player installed on that machine.

change the content type to something like "application/x-download"

if the mime type is unknown to the browser, it should download it ... if it is known, it should run as a downloadable file (possibly in the browser's downloader add-on)
Inspiring
April 8, 2007
There is always the good old anchor tag.
Inspiring
April 9, 2007
quote:

Originally posted by: Dan Bracuk
There is always the good old anchor tag.


Agreed - but I would guess by the question that they want to force the item to always download rather than open up in the default app and or browser plugin.
BKBK
Community Expert
Community Expert
April 8, 2007
<cfheader name="Content-Disposition" value="attachment; filename=music_sample.mp3">
<cfcontent type="audio/mpeg" file="c:\downloads\451ACD47E.mp3">

where c:\downloads\451ACD47E.mp3 is a file on the server and music_sample.mp3 is the name of the file the client will download.

tonysteveAuthor
Participating Frequently
April 10, 2007
Thanks much :)
April 10, 2007
If you are using the <cfheader> tag, its a good practice to place your downloadable files outside of your web dir, so they can't be accessed directly.