www.webdeveloper.com
Results 1 to 11 of 11

Thread: File Download link

  1. #1
    Join Date
    Sep 2005
    Posts
    3

    File Download link

    What i need, is when the user clicks on a link to download a file it opens the standard file save as / open dialog box. The user can then choose a location to save the file and carry on.

    Thanks

  2. #2
    Join Date
    Apr 2005
    Location
    Bathurst, NSW, Australia
    Posts
    3,357
    what sort of file. if you just link to the file then it should automatically prompt this, but if its a webfile like an image or something like that then you can zip it and then just link to the zip, or even add a little note "to download right click and save as"

  3. #3
    Join Date
    Sep 2005
    Posts
    3
    The file is an .mpg. At the moment if i select the link no file dialog box appears. I wondered if there was any java code or something to prompt this. Thanks for your help!

  4. #4
    Join Date
    Sep 2005
    Posts
    1

    Use a content-disposition header

    I had the same problem with a CSV file--I needed the browser to save it to the client's disk, not open it as a spreadsheet. The trick is to include this HTTP header:
    Content-disposition: attachment; filename=<yourfile.mpg>;

    When Internet Explorer sees this, it presents a file download dialog instead of rendering the content. It works for me with Netscape 7 too, as long as popus are enabled.

    See "How To Raise a "File Download" Dialog Box for a Known MIME Type"
    at http://support.microsoft.com/default...0519#appliesto

    If you're an IIS/.NET shop, check "How do I prompt a 'Save As' dialog for an accepted MIME type?" at http://aspfaq.com/show.asp?id=2161

    If you're writing servlets, look at http://www.jguru.com/faq/view.jsp?EID=502939

  5. #5
    Join Date
    Sep 2005
    Posts
    2

    content disposition

    Where do you put this :

    Content-disposition: attachment; filename=<yourfile.mpg>;

    Is it javascript code ?

    Could you give an example ?

    Thank's

  6. #6
    Join Date
    Sep 2005
    Posts
    48
    Code:
    <?php
    if (file_exists($file) ) {  
    	   header('Content-type: application/force-download');
    	   header('Content-Transfer-Encoding: Binary');
    	   header('Content-length: '.filesize($file));
    	   header('Content-disposition: attachment;
    	   filename='.basename($file));
    	   readfile($file);
    	} else {
    	   echo 'No file with this name for download.';
    ?>
    It will display the file download as soon as the page loads.

  7. #7
    Join Date
    Oct 2005
    Posts
    1
    hi

    i actually need to do the exact same thing, except...

    i have a button on my jsp.. let call it "Generate"....
    what i would like to do is.. when the user clicks generate,
    a file is generated (the jsp is displaying a spreadsheet in html, and a csv file
    is generated).. once this file is generated.. i want the user to be prompted
    via a pop-up box and is asked where to save this file...

    any ideas?

    thanks
    tf

  8. #8
    Join Date
    May 2007
    Posts
    2

    File Download Dialog

    Hi Folks

    I too have a Query relative to this thread

    In a JSP page of my site I am showing the .csv file links. When user clicks the link the file download dialog box use to appear to let the user download the file. This was working fine with IE 5.5. But user have shifted their browser version from IE5.5 to IE6.0. And now user do not see the same old download dialog box. The .csv file is getting open in the browser itself. Can anybody help me out? Because the same code was working with IE5.5 but it is not working with IE6.0. What may be the reason behind this?


    I used the Below lines in my JSP page for displaying File Dialog

    response.setHeader("Content-Disposition","attachment; filename="+fileName+";");
    response.setContentType("application/octet-stream");

    Thnkzzz

  9. #9
    Join Date
    Jul 2007
    Posts
    13
    HI,
    I have a similar problem, I tried your suggestions for "Content-disposition" but didn't change any thing.
    I explain my prblem, I have a link on a jsp page normaly when you click the link you get the dialog box (open/save/cancel)
    with firefox it gives the dialog box but with IE it doesn't give the dialog box all the times just for some files
    ,I have different files (.pdf), (.rtf), (.doc), with (.pdf)(.rtf)no problem but with (.doc) files doesn't work for all
    my link is like this:
    ----------------------------------------
    <%if(row.get("cv_id") == null){%><fmt:message key="club.field.yes_no0" bundle="$msg"/><%}
    else
    {%>
    <a href="<%=request.getContextPath()%>/tmp/<%=row.get("filename")%>?id=<%=row.get("employee_id")%>" class="gray"><fmt:message key="club.field.yes_no1" bundle="$msg"/></a>
    ----------------------------------------
    any ideas please.
    thanks
    Last edited by DevSA; 08-02-2007 at 02:09 PM.

  10. #10
    Join Date
    May 2007
    Posts
    2

    Red face To Display File Download Dialog

    In the JSP page put the following two lines of code inside a scriptlet to display a open/save dialog box, which helps the user to choose the location to save the file.

    response.setHeader("Content-Disposition","attachment; filename="<FILENAME>";");
    response.setContentType("application/ms-word");

    The setContentType() paramater is the MIME extn.

    Hope this will help u to display the DownloadDialog in ur application.




    Thnkzzzz

  11. #11
    Join Date
    Jul 2007
    Posts
    13
    Thanks for your reply VIVATHA, but it didn`t change anything, still not working.
    other ideas.
    thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles