CFHEADER & CFCONTENT to dowload a file

Hello everybody,
There are two buttons on my page and depending on which is clicked the code chooses to download either Report_1 or Report_2:
<cfif Form.i_hdn_rpt_1 GT 0>
<CFHEADER NAME="Content-Disposition" VALUE="inline; filename=rpt_1.csv">
<CFCONTENT TYPE="application/csv">rpt_1,1,1<cfabort>
</cfif>
<cfif Form.i_hdn_rpt_2 GT 0>
<CFHEADER NAME="Content-Disposition" VALUE="inline; filename=rpt_2.csv">
<CFCONTENT TYPE="application/csv">rpt_2,2,2<cfabort>
</cfif>
Now what's happening. Say, I click Report_2. It offers (as expected) to download the file rpt_2.csv. Then if I click Report_1 it downloads rpt_1.csv. So far so good. But after this regardless of what is clicked (Report_1 or Report_2) it downloads rpt_1.csv only.
If I begin with Report_1 then no way can I force to download rpt_2.csv.
Could anybody tell me what I am doing wrong?
Thanks,
Alex

Hi BKBK,
Thanks for your response. Here is the simplified code of the form along with the JS function which assigns values to the hidden vars.
function set_hidden(inHdnVarID)
  var oHdn = document.getElementById(inHdnVarID);
  oHdn.value = 1;
<cfform name="myFrm" id="myFrm" action="RptPage.cfm" method="post">
  <table>
    <tr>
      <td>
        <input type="submit" name="sbtn_submit" id="sbtn_submit" value="rpt_1" onclick="set_hidden('i_hdn_rpt_1'); return false">
      </td>
      <td>
        <input type="submit" name="sbtn_submit" id="sbtn_submit" value="rpt_2" onclick="set_hidden('i_hdn_rpt_2'); return false">
      </td>
    </tr>
  </table>
  <input type="hidden" name="i_hdn_rpt_1" id="i_hdn_rpt_1">
  <input type="hidden" name="i_hdn_rpt_2" id="i_hdn_rpt_2">
</cfform>
There is another thing I've noticed. If I change the sequence of the pieces in CF code so that the report_2 comes first then it's the report_2 which gets dowloaded regardless of what button is clicked:
<cfif Form.i_hdn_rpt_2 GT 0>
<CFHEADER NAME="Content-Disposition" VALUE="inline; filename=rpt_2.csv">
<CFCONTENT TYPE="application/csv">rpt_2,2,2<cfabort>
</cfif>
<cfif Form.i_hdn_rpt_1 GT 0>
<CFHEADER NAME="Content-Disposition" VALUE="inline; filename=rpt_1.csv">
<CFCONTENT TYPE="application/csv">rpt_1,1,1<cfabort>
</cfif>
Any ideas?
Thanks again,
Alex

Similar Messages

  • Redirect after using cfheader/cfcontent

    I have a file that a user is prompted to download using
    <cfheader
    name="content-disposition"
    value="attachment; filename=ProPlannerRevenueTemplate.xls"
    />
    <cfcontent
    type="image/jpeg"
    file="#ExpandPath(
    './download_templates/ProPlannerRevenueTemplate_#Left(Hash(session.client_id),
    15)#.xls' )#"
    deletefile="yes" />
    Afterwards, I want to redirect the user to another page, but
    the <cflocation> tag I have after this doesn't seem to
    execute. Any ideas on how to restructure this so that it will
    work?

    I do not think you can do these two operations with the same
    request. A
    <cflocation...> works by sending a client a HTTP status
    of 302 FOUND
    (Moved Temporarily). If the client acted on this status it
    would move
    to the specified URL and not download the file. OR it does
    not act on
    this status and receives this response.
    What you are attempting to do, is probably best done with
    some client
    side code. That uses JavaScript to relocate the client once
    this
    response is received.
    Why this is not currently relocating and sending the file is
    probably
    because of the default reset="yes" parameter of the
    <cfcontent...> tag
    that discards any response generated before the tag.

  • Cfheader /CFcontent producing inconsistent results

    Hi all
    I am using cf header to display a dynically generated report as a word doc. At least this is my goal
    i'm using mx7 on appache 2.0 and Firefox 2.0.0.16 [i can not update this] and ie 6 sp 3 for browsers.
    no matter how a set this up i don't get the expected results
    <cfheader name "content-disposition" value="attachment;filename=#GetInspection.file_number#.doc">
    <cfcontent type="application/vnd.msword">
    in Firefox the file always downloads as a cfm file. I cant change this.
    in ie it down loads as a cfm file but if i elect to save it i can select word.
    the other issue with both browsers is that it will not take on the file name assigned it the cf header tag. It just uses the template name.
    anyone have a suggestion?
    tia
    J

    The equality sign is missing for the name attribute. I also think you have to include the file attribute in cfcontent.
    For example, suppose I have stored the file MyFileName.doc in the web root. When the user opens the page I want the file that is displayed to be named SomeOtherFileName.doc instead. Then some possibilities are:
    1) to download and save file
    <cfset GetInspection.file_number="SomeOtherFileName"><cfheader
    name ="Content-Disposition" value="attachment;filename=#GetInspection.file_number#.doc"><cfcontent
    type="application/msword" file="C:\ColdFusionCentaur\wwwroot\MyFileName.doc"> 
    2) to open and view file in the browser
    <cfset GetInspection.file_number="SomeOtherFileName"><cfheader
    name ="Content-Disposition" value="inline;filename=#GetInspection.file_number#.doc"><cfcontent
    type="application/msword" file="C:\ColdFusionCentaur\wwwroot\MyFileName.doc">

  • Preferred Media Player in Safari? No Dowload This File Button on Real Playe

    Preferred Media Player in Safari? No Dowload This File Button on Real Player?
    Dear Maccies, after years of pain with MS-Windows I recently changed (convcerted?) to OS X. Brought my Real Player with me. Now I have some issues, viewing video files on Safari:
    - How can I tell Safari, that I wish RealPlayer to be used for viewing files (where do I find thsi setting?)
    - How to tel RealPlayer 11 that I want my "Donwload This File" Button back? (Where to find this settin?)
    Please help! Thank you. Best wishes.
    PeterLustig

    Peter, you need to use Flip4Mac.
    http://www.microsoft.com/windows/windowsmedia/player/wmcomponents.mspx
    Hope this helps.

  • cfcontent to send any file type

    I currently use this to serve a download
    <cfcontent type="image/gif" file="F:\main\site.com\userfiles\#getfileinfo.fileid#.gif">
    Is there a way to use this to serve any kind of file. This way I have to specify the file type, but it may change.

    Um... well you could use a variable instead of hard-coding the MIME type?
    Or am I not understanding what you're asking, because that sounds like too obvious a suggestion to me?
    Adam

  • CFContent failing on large files since moving to ColdFusion 9

    Keep getting "The website canno display the page". It is ok when the file is 50MB, but when 300MB or above  - it failed.
    It worked on CF8. We migrated to CF9 during the weekend and all the settings are the same.
    I found that several CF users ran into similar issue - so I know it's not only me like Dan, Tom, etc (http://www.mail-archive.com/[email protected]/msg348532.html//www.mail-archive.com/[email protected]/msg348532.html)
    Thanks,
    Pat.

    This has caused me a bit of a nightmare. When you upgrade versions, you expect things to at least improve. This has to be a priority fix - it's a howling problem!
    Anyhow, for the benefit of others in a similar situation, I eventually got around this by creating a read-only FTP account (literally read-only - the user can't even list files/directories) on our web server and then I use a cflocation redirect instead of the cfcontent approach to serve up the file. I use UUIDs as folder names, so it's a pretty safe way of stopping people from downloading content they shouldn't.
    So, instead of this...
    <cfset Path = "#pathToMyFile#\#myFileName#">
    <cfset FileInfo = GetFileInfo(Path)>
    <cfset FileSize = FileInfo.size>
    <cfset MimeType = getPageContext().getServletContext().getMimeType(Path)> <!--- Sometimes doesn't work, so we need to check that MimeType exists below --->
    <cfheader name="Content-Disposition" value="attachment; filename=""#myFileName#""">
    <cfheader name="Expires" value="#Now()#">
    <cfheader name="Content-Length" value="#FileInfo.size#">
    <cfif IsDefined("MimeType")>
         <cfcontent type="#MimeType#" file="#Path#" deletefile="No">
    <cfelse>
         <cfcontent type="application/octet-stream" file="#Path#" deletefile="No">
    </cfif>
    I now have this...
    <cfset FTPDownloadLink = "ftp://[email protected]/myFTPPath/#myFileName#//[email protected]/myFTPPath/#myFileName#">
    <cflocation url="#FTPDownloadLink#" addtoken="no">
    I suspect that this is actually a better way of doing things anyway, since it offloads responsibility to serving the file from the CF server to the FTP, which is, after all, what it is designed to do.

  • Problem while dowloading the file from Application Server

    Dear Experts,
                 I am facing the Problem while downloading the file from Application server.
    We done the automatic function while saving the invoice, this will create an idoc, and this idoc is written in the Application Server.
    I am running the Transaction AL11 and select the record, and from menu --> List, i am downloading into TXT format.
    But for some segments, the length is long, and so the last 3 to 4 fields values are not appearing in the File. Even though i am unable to view the values in the file before downloading. But i can view in IDOC.
    Please help me to solve this issue.
    Thanks & Regards,
    Srini

    but our user will use the Txn. AL11 and they will download from there
    Educate the user On a serious note, tell him this is not how data from app server should be downloaded. You can ask him to talk to the basis team to provide him access to the app server folder where the file is being stored.
    I can set the Variant and put this in background, But always the file name will be change, Like we use Time stamp in the File name.
    You can't automate this process by scheduling in BG mode. This is because the in BG mode you can't dwld the file to presentation server.
    Hope i'm clear.
    BR,
    Suhas

  • SCCM2012 R2 intune - Cannot dowload csr file APN from SCCM console

    I want to enroll IOS device, but when i want to generate csr, after successful login on intune, i have a message "Service unavailable". So, i can't download csr file. The
    Management for windows phone
    works as well as for android.

    Hi,
    i followed up a case to Microsoft. They mentioned that the MDM authority has already been reset previously (test period) and they have compléted a procédure to allow me to use APN certificate. I have made a new test and now i can add the apn certicate.
    i.

  • Dowload a file using HTTPS

    I am trying to write some code that'll connect with an external server (via the proxy) and ownload a file using the HTTPS protocol.
    All I can find is how to get a stream to such file and read it line for line.
    Many thanks.

    Forget the lines. Just read and write bytes.
    int count;
    byte[] buffer = new byte[8192]; // or more
    while ((count = in.read(buffer)) > -1)
      out.write(buffer, 0, count);
    out.close();
    in.close();

  • Why every time I dowload a file in firefox I have to refresh the desktop in windows 7 to see it?

    explorer work fine when I used it to downloads files. I use windows 7 .....but when I use firefox to downloads files I have to refresh the desktop to see downloaded files.

    You need to install the release candidate, the problem is in the beta 12.

  • Question about dowloading quicktime files

    Anyone know how I can enable people to download the quicktime files and or aac/mps files I have on my iweb space? I have a page with a Garageband tune I did, and people can listen to it, but I want them to be able to download it to the computers.
    thanks in advance.

    Saving QuickTime content viewed in a Web page requires the Pro upgrade.
    The easiest solution is the place the files in your iDisk Public folder.
    If you use Homepage (not iWeb) you can make a simple file sharing page that will automatically update as your Public folder changes. You can add this URL to your iWeb pages.
    You can also "link" your Public folder files (so you don't have to upload them twice) to other pages.
    The address (URL) would use this syntax:
    http://homepage.mac.com/accountname/.Public/filename.fileextension
    Where accountname is your .Mac account and filename.filextension is the name of the file and the file extension (.mov, .mp3 etc.).
    Notice the period (.) and the capital P in Public.

  • How to dowload a file to a cd?

    How do I download a file to a cd?

    Go to Finder Help and you can get this information:
    Ciao.

  • Dowload exercise files

    Is there a place to download the files for the exercises in  the Adobe tutorials for Premier Pro 4?

    Welcome to the forum.
    I agree with Curt - which tutorials? There are tons, all over the Internet. Each might be different, and have different requirements.
    Good luck, and we'll be looking for the details.
    Hunt

  • Cfcontent/cfheader doesn't support file pause/resume.

    I'm testing the possibility of using cfcontent to serve my file downloads for security purposes. Files in the web root seem to be open to all on the web but I can use cfcontent to serve files from an otherwise unaccessable directory. The downloads are working great but they cannot be paused or resumed in a download manager. Am I doing something wrong or what?
    Here's my code;
    <cfif isdefined('url.downloadpath')>
        <cfheader name="Content-Disposition" value="attachment; filename=#replace(url.filename,' ','_','all')#">
        <cfheader name="Content-Length" value="#url.filesize#">
        <cfheader name="Content-Type" value="application/octet-stream">
        <cfheader name="Content-Location" value="./?#query_string#">
        <cfcontent type="application/octet-stream" file='#url.downloadpath##url.filename#'>
        <cflocation addtoken="no" url="./?#left(query_string,find('&downloadpath')-1#">
    </cfif>
    Thanks,
    Jon

    Where did you learn that turning the iPod off and later turning it on takes more power from the battery than leaving it in sleep mode? I'm not saying that you are wrong, just interested where this info came from.

  • How can I make the browser use the proper filename during a forced save, using CFCONTENT/CFHEADER

    We have a client using CF8 Server for a site and I am using the CFHEADER/CFCONTENT method to force a file to save to the end-user's computer.
    The dialogue comes up as expected, but regardless of what is found in the CFHEADER for a filename, it tries to save the file as the CFM page name.
    i.e. The CFM page is signature.cfm. I am trying to make it save a TXT file to the user's computer, which it seems to be trying to do, but the instead of using "sig.txt" as the filename as outlined in the CFHEADER, it is defaulting to "signature.cfm"
    While I know that I could change the name and extension and the content in the file would be correct, the mass majority of end-users will not know that they can do that, and the client does not want it to become more complicated than necessary.
    Is there a way to make the file change to the proper name in the SAVE AS dialogue?
    Thanks in advance.
    Code so far is pretty straight forward ...
    <CFHEADER name="Content-Disposition" value="attachment; filename=sig.txt">
    <CFCONTENT type="application/unknown" file="#xf#">

    I'm guessing the type="application/unknown" is interfering. Try type="text/plain".

Maybe you are looking for