Skip to main content
Inspiring
April 2, 2009
Question

Save As Function

  • April 2, 2009
  • 1 reply
  • 4411 views
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 has been closed for replies.

1 reply

Inspiring
April 2, 2009
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.



Inspiring
April 7, 2009

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

April 15, 2009

Okay, here is what I get when I look at the "Save File" in Notepad...

An error has occured, please click the back button on your browser.

Here is my code again and I think I've tried everything you suggested.

on the "users_index.cfm" page

This one doesn't work as it should

<a href="save.cfm?filename=#dir.name#"><font face="Arial"><strong>#dir.name#</strong></font></a><br/>
This works fine but not what I need to work.          
<a href="users/#GetName.file#/#dir.name#" target="_blank"><strong>#dir.name#</strong></font></a><br/>

Here is what is on my "save.cfm" file.

<cfheader name="expires" value="#NOW()#">
<cfheader name="content-disposition" value="attachment; filename=#filename#">
<cfsetting showdebugoutput="false">
<cfcontent type="application/pdf" file="users/#GetName.file#/#filename#" deletefile="no" reset="yes">

Could it be that a setting on my server is causing this issue? or any other settings I may be missing?

thanks for helping.


Well, looking at the content of the downloaded file (...Error occured...) - sounds like your path may be incorrect and cfcontent is not finding the file to download (or permission errors may have occured).  In save.cfm, before you do the cfcontent call, put the following in:-

<cfoutput>#FileExists('users/#GetName.file#/#filename#')# (users/#GetName.file#/#filename#)</cfoutput><cfabort>


...Actually, looking at that, it is a relative path, not an absolute - this could be the problem...  cfcontent may need the file path all the way from the root directory (c:\ in windows - / in linux).

If you get 'YES' users/xxx/xxx - then I'm stumped.  If you get 'NO' it means your path is incorrect, and you need to work it out with an expandpath() call beforehand. Is the users directory in the same directory as the save.cfm file?  If so, try

<cfcontent type="application/pdf" file="#Expandpath('users/#GetName.file#/#filename#')#" deletefile="no" reset="yes">

which will expand the path from a relative to an absolute path.

GIve those a try and let us know how you get on.