⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 view_attachment.aspx

📁 Bug管理系统
💻 ASPX
字号:
<%@ Page language="C#"%>
<!-- #include file = "inc.aspx" -->
<script language="C#" runat="server">

//Copyright 2002-2005 Corey Trager
//Distributed under the terms of the GNU General Public License


int id;
int bug_id;
String sql;
DbUtil dbutil;
Security security;

///////////////////////////////////////////////////////////////////////
void Page_Load(Object sender, EventArgs e)
{

	dbutil = new DbUtil();
	security = new Security();
	security.check_security(dbutil, Request, Response, Security.ANY_USER_OK);

	string var = Request["id"];
	id = Convert.ToInt32(var);

	var = Request["bug_id"];
	bug_id = Convert.ToInt32(var);
	
	var = Request["download"];
	bool download;
	if (var == null || var == "1")
	{
		download=true;
	}
	else
	{
		download=false;
	}


	sql = @"select ba_file, isnull(ba_content_type,'') [ba_content_type] from bug_attachments where ba_id = $1";
	sql = sql.Replace("$1", Convert.ToString(id));
	DataRow dr = dbutil.get_datarow(sql);
	
	string filename = (string) dr["ba_file"];
	string content_type = (string) dr["ba_content_type"];

	// create path
	string upload_folder = Util.get_setting("UploadFolder","c:\\");
	StringBuilder path = new StringBuilder(upload_folder);
	path.Append("\\");
	path.Append(Convert.ToString(bug_id));
	path.Append("_");
	path.Append(Convert.ToString(id));
	path.Append("_");
	path.Append(filename);

	if (System.IO.File.Exists(path.ToString()))
	{

		if (content_type == null || content_type == "")
		{

			string ext = System.IO.Path.GetExtension(path.ToString()).ToLower();

			if (ext == ".txt")
			{
				Response.ContentType = "text/plain";
			}
			else if (ext == ".gif")
			{
				Response.ContentType = "image/GIF";
			}
			else if (ext == ".jpeg" || ext == ".jpg")
			{
				Response.ContentType = "image/JPEG";
			}
			else if (ext == ".doc")
			{
				Response.ContentType = "application/x-msword";
			}
			else if (ext == ".xls")
			{
				Response.ContentType = "application/x-msexcel";
			}
			else if (ext == ".zip")
			{
				Response.ContentType = "application/zip";
			}
			
		}
		else
		{
			Response.ContentType = content_type;
		}
		

		if (download)
		{
			Response.AddHeader ("content-disposition","attachment; filename=" + filename);
		}
		else
		{
			Response.AddHeader ("content-disposition","inline; filename=" + filename);
		}



		Response.WriteFile(path.ToString());


	}
	else
	{
		Response.Write ("File not found:<br>" + path.ToString());
	}


}

void Page_Unload(Object sender, EventArgs e)
{
	if (dbutil != null) {dbutil.close();}
}

</script>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -