Hi all,

I am giving the href to give a link to a file.
The problem is that in IE it opens the text files in the same browser, but in mozilla it works fine(gives prompt of save as option).


I want the same functionality for IE also, searching Google I found so much solution but all were saying about writing php.

I don't want to implement php, can it be done simply using by HTML,jsp and struts tag.

Regards,

Recommended Answers

All 6 Replies

I don't think you need php, but you will probably have to use some javascript or something if you want to force the link to be downloaded or saved.

You could use the target link attribute if you just need to stop it from opening in the same window as your current page.

I dont want to open it at all, what I want is the save as option should pop up. Like if some junk extension file you will give it will do.

File.asdf Link will give save as pop up
File1.doc or .txt will open the content of the file in the browser window.

Type the following magical incantation next to the link

"To save the file, right click the link and select Save as.."

Then the powers of darkeness and psychic forces extraordinary are invoked when the user does as he/she is told, and they can save the file.

Great reply drjohn, thanks for the same. But I am looking for some concrete solution. How we can pop up a window when user clicks on the link.

Well, a quick check using the keyword 'force download', indicates you can force downloads, but it isn't easy. The easiest way is to simply zip the file you want to have downloaded, since zipped files are always downloaded.

one way
<a href="pathto/savefile.php?file=pathtosomefile.txt">download somefile.txt</a>
savefile.php is below

<?php $file=$_GET['file'];
if(!$file) return false;
header("Content-disposition: attachment; filename=$file");
header('Content-type: text/plain;');
readfile("$file");
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.