<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %><%@page import="webber.core.*, java.io.*, webber.wbst.com.download.*"%> <% //判断refer, 禁止盗链 String referer = request.getHeader("referer"); if(referer == null || referer.equals("")) { out.println("禁止盗链, 请从本网站上下载!"); return; } String serverstr = request.getScheme() + "://" + request.getServerName(); if(!referer.startsWith(serverstr)) { out.println("禁止盗链, 请从本网站上下载!"); return; } DownLoadNewsAttach attach=new DownLoadNewsAttach(request); String realPath=attach.getRealPath(); String filename=attach.getFilename(); java.io.File f = new java.io.File(realPath); if(!f.exists()) { out.print("
找不到文件!!
"); return; } String filetype= "application/octet-stream";// 告诉客户端为文件流 FileInputStream fis = null; try { long filesize = f.length(); fis = new FileInputStream(f); response.reset(); response.setContentType(filetype); response.setHeader("Content-length", Long.toString(filesize)); response.setHeader("Content-disposition", "attachment; filename=" + StringUtil.encodeDownloadFileName(request, filename)); OutputStream fout = response.getOutputStream(); byte[] buf = new byte[4096]; int count; while((count = fis.read(buf)) != -1) { fout.write(buf, 0, count); } //更新浏览次数 attach.updateBrowerTimes(); fis.close(); fis = null; fout.close(); } catch(Exception e) { //System.out.println(e.getMessage()); } finally { try { if(fis != null) { fis.close(); } } catch(Exception e) { } } out.clear(); out = pageContext.pushBody(); %>