日期:2014-05-16 浏览次数:20489 次
<%
Dim Scs,ture_url,filename,exe_name,Range,file_name,file_url
file_url=Request.QueryString("file")
ture_url=server.MapPath(file_url)
file_name=Mid(ture_url,instrRev(ture_url,"\")+1)
exe_name=Mid(file_name,instrRev(file_name,".")+1)'后缀名
If InStr("asp,pnp,aspx",LCase(exe_name))=0 Then '禁止下载一些程序文件
filename=Mid(file_name,1,instrRev(file_name,".")-1)'文件名
Set Scs=CreateObject("Adodb.Stream")
Scs.Mode=3
Scs.Type=1
Scs.Open
Scs.LoadFromFile(ture_url)
Response.ContentType="application/octet-stream"
Response.AddHeader "Content-Disposition:","Attachment;filename="&Server.UrlEncode(filename)&"."&exe_name
Response.BinaryWrite(Scs.Read)
Else
Response.write "非法下载文件"
End If
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page contentType = " text/html; charset=utf-8" %>
<%@ taglib uri = "/struts-tags" prefix = "s" %>
<%@page import="java.util.*"%>
<%@page import="java.io.*"%>
<%@page import="java.net.*"%>
<%
String filename = "";
String nofile ="";
if(request.getParameter("nofile")!=null){
nofile = URLDecoder.decode(request.getParameter("nofile"),"UTF-8");
}
if (request.getParameter("file") != null) {
filename = request.getParameter("file");
}
filename=URLDecoder.decode(filename,"UTF-8");
String disp_file = request.getParameter("filename")!=null?
URLEncoder.encode(filename.substring(filename.lastIndexOf("/")+1),"UTF-8"):URLEncoder.encode(request.getParameter("filename"),"UTF-8");
System.out.println("disp_file---="+disp_file);
filename=request.getRealPath("/")+filename;
System.out.println("filename="+filename);
File file = new File(filename);
if(file.exists()){
System.out.println("==filename="+filename);
response.setContentType("application/msword");
response.setHeader("content-disposition","attachment; filename="+disp_file);