Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 28th, 2005, 07:46 AM
Registered User
 
Join Date: May 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to kalyansarkar108
Default link to download a file

I have a jsp page that contains a link to a file. On clicking the link the file opens in the browser itself. I want to give an option "Would you like to open the file or save it to your computer?". How can I do this? Can anyone help?

Here is my code...

<td class="tbdataleft" align="left"><a href='file:C:/file.doc' class="red">file.doc</a></td>
 
Old November 28th, 2005, 09:21 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

The open/save dialogue appears automatically if the file is of a type the browser does not understand.

To force an open/save dialogue, you must alter the HTTP response headers. I don't know how it's done in JSP, but in PHP it looks like this:

Code:
// Put in whatever MIME type or leave this one
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename=suggested_file_name.whatever');

// Grab and output the contents of the file.
echo file_get_contents('/server/path/to/file.whatever');
HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design





Similar Threads
Thread Thread Starter Forum Replies Last Post
Encrypted URL download link benjamr Beginning PHP 1 October 5th, 2008 07:36 PM
How to provide download link for images snowbydave1 Beginning PHP 4 March 24th, 2007 04:38 AM
How to provide download link for images snowbydave1 Pro PHP 0 March 19th, 2007 02:06 AM
How to provide download link for images snowbydave1 PHP Databases 0 March 19th, 2007 02:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.