国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

ASP和C#隱藏文件下載路徑的方法

2024-05-04 11:06:39
字體:
來源:轉載
供稿:網友
中國最大的web開發資源網站及技術社區,

  關于下載路徑的隱藏都是通過傳遞一個數據庫中的id,然后在另外一張頁面通過傳遞的id在數據庫中讀出路徑。

  1、c#中實現的方法(只需要.aspx.cs的代碼就可以了)

string sel_sql="select filevisualpath from tabmailattachfiles where fileid="+request.querystring["destfilename"].tostring();

//   string destfilename = request.querystring["destfilename"]!=null?request.querystring["destfilename"]:"";
   string destfilename=roa.components.fune_commerce.execad(sel_sql).tables[0].rows[0][0].tostring();
   destfilename = server.mappath(".")+destfilename;
   destfilename = server.urldecode(destfilename);
   if(file.exists(destfilename))
   {
    fileinfo fi = new fileinfo(destfilename);
    response.clear();
    response.clearheaders();
    response.buffer = false;
   
    //response.appendheader("content-disposition","attachment;filename=" +httputility.urlencode(path.getfilename(destfilename),system.text.encoding.default));
    response.appendheader("content-disposition","attachment;filename=" +httputility.urlencode(path.getfilename(destfilename),system.text.encoding.utf8));
    response.appendheader("content-length",fi.length.tostring());
    response.contenttype="application/octet-stream";
    response.writefile(destfilename);
    response.flush();
    response.end();
   }
   else
   {
    response.write("<script langauge=javascript>alert('文件不存在!');history.go(-1);</script>");
    response.end();
   }

  2、在asp中的實現方法

<!--#include file="conn.asp" -->
<%
response.buffer = true
response.clear
dim url
dim fso,fl,flsize
dim dname
dim objstream,contenttype,flname,isre,url1
'*********************************************調用時傳入的下載文件名
m_id=trim(request.querystring("id"))
set rs=server.createobject("adodb.recordset")
sql="select * from dataview where xsf=true and id="&m_id
rs.open sql,conn,1,1
if not rs.eof then
    dname=rs("path")
else
    response.write("no found")
    response.end
end if
rs.close:set rs=nothing
'*********************************************
if dname<>"" then
'******************************下載文件存放的服務端目錄
url=server.mappath(dname)
else
    response.write("no found")
    response.end 
end if
set fso=server.createobject("scripting.filesystemobject")
set fl=fso.getfile(url)
flsize=fl.size
flname=fl.name
set fl=nothing
set fso=nothing
set objstream = server.createobject("adodb.stream")
objstream.open
objstream.type = 1
objstream.loadfromfile url
select case lcase(right(flname, 4))
case ".asf"
contenttype = "video/x-ms-asf"
case ".avi"
contenttype = "video/avi"
case ".doc"
contenttype = "application/msword"
case ".zip"
contenttype = "application/zip"
case ".xls"
contenttype = "application/vnd.ms-excel"
case ".gif"
contenttype = "image/gif"
case ".jpg", "jpeg"
contenttype = "image/jpeg"
case ".bmp"
contenttype = "image/bmp"
case ".ppt"
contenttype = "application/vnd.ms-powerpoint"
case ".mdb"
contenttype = "application/x-msaccess"
case ".wav"
contenttype = "audio/wav"
case ".mp3"
contenttype = "audio/mpeg3"
case ".mpg", "mpeg"
contenttype = "video/mpeg"
case ".rtf"
contenttype = "application/rtf"
case ".htm", "html"
contenttype = "text/html"
case ".txt"
contenttype = "text/plain"
case else
contenttype = "application/octet-stream"
end select
response.addheader "content-disposition", "attachment; filename=" & flname
response.addheader "content-length", flsize
response.charset = "utf-8"
response.contenttype = contenttype
response.binarywrite objstream.read
response.flush
response.clear()
objstream.close
set objstream = nothing
%>

出處:『 漂失在藍天下的云 』 blog

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 漾濞| 万州区| 洮南市| 喀喇| 莲花县| 铅山县| 永宁县| 石嘴山市| 扬州市| 洪雅县| 西丰县| 无锡市| 宝丰县| 衡阳县| 江源县| 贵德县| 屏山县| 巨野县| 乌什县| 迭部县| 湖北省| 汝阳县| 上饶县| 米易县| 新竹县| 潮安县| 勐海县| 中超| 台南县| 尼木县| 阿拉善左旗| 西乡县| 赤峰市| 辉县市| 清河县| 丹棱县| 龙陵县| 富蕴县| 斗六市| 娄底市| 汕头市|