Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Downloading file thru CFCONTENT 1

Status
Not open for further replies.

ketankshah

IS-IT--Management
Jan 11, 2001
121
IN
I want to download an XLS or a PDF file from the site. I tried this on my local webserver.

1. When my files are in CFDOCS directory and my calling .cfm page is also in the same directory it downloads the file but if I move these files to my application directory i.e. CFIDE\myapps, it is showing me this error.

"Internet Explorer was not able to open this internet site. The requested site is either unavailable or cannot be found. Please try again latter."


My script is

<CFCONTENT TYPE=&quot;application/msexcel&quot;
FILE=&quot;#GetDirectoryFromPath(GetTemplatePath())#data\testdoc.xls&quot; DELETEFILE=&quot;No&quot;>

Why is so?

2. When I downloaded the file from CFDOCS, as mentioned in point 1, it downloaded with the name of the calling cfm file i.e. download.cfm. How to maintain the same name while downloading the file ?

Ketan
 
Correcting my first point, I change in the cfcontent.cfm in the CFDOCS\snippets folder and ran the file thru the language reference documentation by going to the CFCONTENT Tag help and running Example, it downloaded the file with runexample.cfm name but while running the same tag from an independent cfm page it it giving me the above error whereever I stored the files.

Please help.

Ketan
 
It would help to know what specific error message you're getting. The problem with IE is that it hides the specific webserver error such as &quot;404&quot;, &quot;500&quot;, etc.. If you can try this in Netscape, let me know what the specific error message is as that will give a clue as to the problem.

GJ
 
I managed to sort out my first problem. It was because of some settings in web server configuration. Now I am stuck with the second problem. I get the &quot;Save as&quot; dialogue box but the default file name it shows is download.cfm in IE and download.xls in Netscape if the file original file name is data.xls. Every time the user has to change the file name. How can we show the original file name in the &quot;Save as&quot; dialogue box.

Ketan
 
I don't believe there is any standard way to do this. The save-as feature is browser specific and will usually default to the name of the requested page. The only suggestion I could make is configure your webserver to treat .xls extensions the same as .cfm and rename your script to &quot;data.xls&quot;. This should cause any browser to put the correct name in the save-as box.

GJ
 
Your suggestion holds good when there is a fix file to download. My site is having a facility to download the file whose name is being retrieved from the database. Any suggestion ?
 
I'm afraid I can't think of anything that would help in that case. The only suggestion I would have is to try making the links ftp links such as &quot;ftp://servernam/filename.ext&quot;. I rarely use them so I don't know if it will do what.

One other thing I just thought of is having your .cfm page re-direct to the actual file name instead of returning it via cfcontent. Is there any reason you can't create a direct link to it?

GJ
 
I didn't get you. Please can you write me how can I do this redirection ?
 
If the file is in the directory &quot;D:\files&quot; and this directory is configured in the web server as &quot; you could do this:

<cflocation url=&quot; addToken=&quot;no&quot;>

This would provide a direct link to the file in question so the name should be correct in the dialog box.

Let me know if you have any trouble,
GJ
 
I used CFLOCATION tag as per your suggestion but it work exactly like HREF tag. Here it is giving me the correct file name but it is opening XLS file on the browser instead of giving me the download dialogue box. In pdf file it is opening the dialogue box to download. This is in Internet Explorer.

Again this behaviour is different in Netscape. Here in both types of files it is opening the download dialogue box as per the need.

How can I force download dialogue box to appear irrespective of the browser and its settings ? Is there any settings which I can give in my cfm page to force the download instead of opening the file. My client doesn't want to open the file straightaway in the browser. He needs the visitor's interaction by popping up the download dialogue box.

Thanks for the above suggestions.

Please help.

Ketan
 
Hey Ketan,

I don't believe there is anything you can do to force the browser to display a dialog box. This is browser specific behavior and depends on how the browser has been configured. With Netscape, someone may have installed a plugin to view excel documents. In this case, Netscape will see the document as one it can handle with the help of a plugin. It will not prompt the user to save the document but will display it by default since this is how it has been configured. If you are dealing with a corporate environment where you can be assured of what browser the visitors will use and know how it's configured, you can guarantee the correct behavior. In the case of Internet visitors, you have no way of knowing how their browser has been configured to handle a specific document type.

There may be some newer syntax that Netscape or IE will recognize as a command to display the save-as dialog but I think you will find that it is not widely supported if it exists. Did you try the ftp:// link instead of the http:// link? That might work better as ftp is geared more towards saving files instead of viewing them but I still don't think the display behavior is any standard even in that case.

Sorry I couldn't give you a solution but I don't think it's possible to reliably do what you want.

GJ
 
This calling file download server page is a problem specifically when using IE5.5 service pack 1. I'm not sure what the exact reason is for this, but this is in fact a bug with that update. The problem deals with scripts calling files for download. Try using Netscape to see if it works correctly.

minsan
 
I tried changing the path from http:// to ftp:// but then it stops finding the page and was giving the page not found error. Is this the only thing I have to change ? My path is &quot; and I have changed it to &quot;ftp://webserver/cfide/trial/data/struc.xls&quot;. What other changes I have to make ?
 
You will need to configure your ftp server so that the ftp path corresponds to the same directory. When you use the &quot;ftp://&quot; link, the browser will try to communicate with your ftp server instead of your webserver.

GJ
 
OK. I will try to configure the ftp server and if I have some problem after that I will come back to you again.

Thanks for all your valuable support.

Ketan
 
Just check the Yahoo site. Try receiving a mail having an XLS file attached. It gives you 3 options. Scan, View and download. If you click the download option, though the link is thru HREF tag, it downloads the file irrespective of the browser and its settings. Ofcourse, it is passing some parameter in the URL. I have tried to do the same in a machine where it was opening the XLS file in the browser and it downloaded the file thru yahoo after showing me the download dialogue box. There must be something which is forcing it to download.
Can anybody has an idea, how this has been done ?
 
To start the download, do you click a link or a button? If it's a link, can you post the exact link? If it's a form button, can you post the code between the form tags? You may want to alter any values that indicate your account and password.

As I mentioned earlier, there may be some syntax that works with newer browsers to do this and you may have found an example of it.

GJ
 
try rewriting the http headers with cfcontent, and setting the 'content-disposition' attribute to 'attachment'
 
Hit upon this page when looking for a solution to errors i am getting on my web page. Its exactly the smae as your first point in the initial question. Can u please let me know how u managed to solve it(&quot;Internet Explorer was not able to open this internet site. The requested site is either unavailable or cannot be found. Please try again latter&quot;). Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top