View Full Version : Download file instead of navigate to URL
Is it possible to create link that will start file download ("Save target as...") instead of navigate to URL?
Thanks in advance for any suggestions.
12-15-2002, 05:48 PM
i think it's possible in IE, but not cross browser. the best way to make it happen cross browser, is to zip it, as most browsers are set to automatically download zip files.
The best solutions I come with are:
to use ExecWB of IE or to zip target file.
Still may be there is some other trick out there?
12-15-2002, 06:16 PM
There is a method in IE called execCommand; it goes something like
MSDN will have more ....
... but, it is IE only. The way to acheive this is server side. In PHP you make this file called "download.php":
$saveName = stripslashes($HTTP_GET_VARS["name"]);
$savePath = stripslashes($HTTP_GET_VARS["path"]);
header ("Content-Type: application/octet-stream");
header ("Content-Disposition: attachment; filename=$saveName");
header ("Content-Transfer-Encoding: binary");
And then you call it with a link like this:
Thanks, brothercake, it work like magic.
Here mine interpretation in ASP for anyone interesting:
Response.AddHeader "CONTENT-TYPE", "application/octet-stream"
Response.AddHeader "CONTENT-DISPOSITION", "attachment; filename=" & Request.QueryString("Name").Item
Response.AddHeader "CONTENT-TRANSFER_ENCODING", "binary"
dim fso, f, ts
set fso = CeateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(MapPath(Request.QueryString("Path").Item))
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
You can call it with:
<a href="download.asp?Path=test.txt&Name=saveas.txt">Click here to download</a>
12-15-2002, 08:11 PM
12-15-2002, 08:53 PM
i'm gonna move this to the General Web Building forum. is this maybe one that we want to put in the archives?
12-15-2002, 08:57 PM
I would say yes, john - this question pops up so much etc. and this thread is a good answer :)
::] krycek [::
12-18-2002, 12:21 AM
That covers the IE side of it. For Mozilla/Netscape, you shift-click the link to Save As...
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.