Skip to main content
Inspiring
Apr 2, 2009 9:43 PM UTC
Question

Save As Function

I have several files listed on my .cfm using <cfdirectory>, this works perfect, lists, the .pdf's, .xls, etc. Now they open but I don't want my users to open them, I want them to be forced in Saving these files onto their own machine then they can open them. I tried using <cfcontent> and <cfheader> but it's not working the way I want. Right now I'm using the attached code, we like this formatting but I can't figure out how to get these documents to save. Any ideas? Thanks.
This topic is closed to new replies. Start a new post to keep the conversation going.

11 replies

Inspiring
Apr 2, 2009 10:16 PM UTC
still_smiling wrote:
> I have several files listed on my .cfm using <cfdirectory>, this works perfect,
> lists, the .pdf's, .xls, etc. Now they open but I don't want my users to open
> them, I want them to be forced in Saving these files onto their own machine
> then they can open them.

To be exact, these files *are* saved on the users machine before they
are opened. Albeit in the browsers 'temporary files' directory of which
many users are not very aware.

> I tried using <cfcontent> and <cfheader> but it's not working the way I want.

You can use <cfcontent...> and <cfheader...> to do this, but you must
use an unknown mime type for the content. If the browser knows the mime
type it will use any plug-ins it has been configured to use and you have
no control over this. But if the browser does not know the mime type
the only thing it can do is offer the user to download the file.



Translate
Inspiring
Apr 7, 2009 9:46 PM UTC

Still can't get this to work properly so I'm going to post my code and see if anyone can help out with this "Save As" function.


The first page has the following code:

The SQL statments pulls the files so the user can select which file they wish to save. It could be a .pdf, .xls or even a .qbw file

<a href="save.cfm?filename=#dir.name#" target="_blank"><font face="Arial"><strong>#dir.name#</strong></font></a>

The second page, save.cfm has the following code:

<cfheader name="Content-Disposition" value="attachment; filename=#filename#">           
<cfcontent type="unknown" file="users/#GetName.file#/#filename#"  deletefile="No">

Not sure if it makes a difference that I'm doing this with an https.

Thanks in advance, this thing is really driving me crazy.

Courtney

Translate
ilssac
Inspiring
Apr 7, 2009 10:23 PM UTC

<cfcontent type="unknown" file="users/#GetName.file#/#filename#"  deletefile="No">

<cfheader name="Content-Disposition" value="attachment; filename=#GetFile.FileName#">
<cfcontent type="application/octet-stream" file="users/#GetName.file#/#filename#"  deletefile="No">

Maybe, you are fighting the Browser builders who do their best to make this automatic for the users and they have built logic that looks at file extensions as well as file types to make a guess on how to handle delivered content.

Translate