主题: 在编辑器中增加.net上传功能(提供下载) |
作者: 青春一度, 发布日期: 2007-11-12 09:58:10, 浏览数: 6978 |
之前发过源码,有的朋友说不会用,这几天有空整理出来了供大家下载。
到我博客中下载: http://blog.csdn.net/adleyliu/archive/2007/11/12/1879790.aspx using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; /* #********************************************************* #文件名称: UpLoad.aspx.cs #功能描述: 上传文件类 #程序制作:留印(adleyliu) #联系qq :14339095 #联系邮箱:adleyliu@163.com #官方网站: http://www.115000.com.cn #Copyright (C) 2007-2008 115000.com.cn all rights reserved. #最后更新: 2007-11-11 #注:转发时请保留此声明信息,这段声明不并会影响你的速度! #如有修改请将修改后的文件以邮件形式发送给作者一份,谢谢! #支持多文件上传功能 #********************************************************* */ public partial class upload_cgi : System.Web.UI.Page { // protected System.Web.UI.WebControls.Button UploadButton; // protected System.Web.UI.WebControls.Label strStatus; protected void Page_Load(object sender, EventArgs e) { /// 在此处放置用户代码以初始化页面 if (!this.IsPostBack) this.SaveImages(); } private Boolean SaveImages() { liuyinconn yldate = new liuyinconn();//时间类 string filepath = "../liuyin_UploadFile/";//文件目录 string filepathdate = "" + yldate.yldate(System.DateTime.Now, "y-m-d") + "";//当天目录 string imgWidth = Request.Form["imgWidth"]; string imgHeight = Request.Form["imgHeight"]; string imgBorder = Request.Form["imgBorder"]; string imgTitle = Request.Form["imgTitle"]; string imgAlign = Request.Form["imgAlign"]; string imgHspace = Request.Form["imgHspace"]; string imgVspace = Request.Form["imgVspace"]; //'遍历File表单元素 HttpFileCollection files = HttpContext.Current.Request.Files; // '状态信息 System.Text.StringBuilder strMsg = new System.Text.StringBuilder(); try { for (int iFile = 0; iFile < files.Count; iFile++) { //'检查文件扩展名字 HttpPostedFile postedFile = files[iFile]; string FileName; FileName = System.IO.Path.GetFileName(postedFile.FileName);//获取初始文件名 if (FileName != "") { string fileExtension = System.IO.Path.GetExtension(FileName);//获取文件扩展名 if (fileExtension != ".gif" && fileExtension != ".jpg" && fileExtension != ".jpeg" && fileExtension != ".bmp" && fileExtension != ".png") { Response.Write("<div style="font-size:12px;color:#333333;padding-top:0px;">上传失败!1[ <a style="CURSOR: pointer" onclick=history.go(-1) ><font color=red>重新上传</font></a> ]</div>"); Response.End(); } string photoName2 = "" + yldate.yldate(System.DateTime.Now, "yyyy-m-d-h-m-s-ms") + "_" + iFile + "" + fileExtension; //重新为文件命名,时间毫秒部分+文件大小+扩展名 System.IO.Directory.CreateDirectory(@Server.MapPath("" + filepath + "" + filepathdate + ""));//生成文件完整目录 //'可根据扩展名字的不同保存到不同的文件夹 //注意:可能要修改你的文件夹的匿名写入权限。 postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("" + filepath + "" + filepathdate + "/") + photoName2); //插入图片,关闭层 string file_url = "" + filepath + "" + filepathdate + "/" + photoName2+""; Response.Write("<html>"); Response.Write("<head>"); Response.Write("<title>Insert Image</title>"); Response.Write("<meta http-equiv="content-type" content="text/html; charset=utf-8">"); Response.Write("</head>"); Response.Write("<body>"); Response.Write("<script>parent.KindInsertImage(""+file_url+"",""+imgWidth+"",""+imgHeight+"",""+imgBorder+"",""+imgTitle+"",""+imgAlign+"",""+imgHspace+"",""+imgVspace+"");</script>"); Response.Write("</body>"); Response.Write("</html>"); /* Response.Write("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>"); Response.Write("上传后文件地址:" + filepath + "" + filepathdate + "/" + photoName2 + "<br>"); Response.Write("上传文件的文件名:" + FileName + "<br>"); Response.Write("上传文件的扩展名:" + fileExtension + "<br><hr>"); */ } else { Response.Write("<div style="font-size:12px;color:#333333;padding-top:0px;">上传失败!2[ <a style="CURSOR: pointer" onclick=history.go(-1) ><font color=red>重新上传</font></a> ]</div>"); Response.End(); return false; } } //显示是否成功! Response.Write("<div style="font-size:12px;color:#333333;padding-top:0px;">文件已经成功上传![ <a style="CURSOR: pointer" onclick=history.go(-1) ><font color=red>继续上传</font></a> ]</div>"); return true; } catch (System.Exception Ex) { Response.Write("<div style="font-size:12px;color:#333333;padding-top:0px;">上传失败!3[ <a style="CURSOR: pointer" onclick=history.go(-1) ><font color=red>重新上传</font></a> ]</div>"); Response.End(); return false; } } //写入到编辑器 //Response.Write("<script type="text/javascript">parent.document.KindEditorForm.document.body.innerHTML+='<a href="" + filepath + "" + filepathdate + "/" + photoName2 + "" title=点击放大 target=_blank><img onmousewheel="return imgzoom_b_s(this);" alt=CTRL+鼠标滚轮放大或缩小 src="" + filepath + "" + filepathdate + "/" + photoName2 + "" onload="return imgzoom(this,480)" border=0></a><br><br>';</script>"); } |
作者: 青春一度, 发布日期: 2007-11-12 17:33:01 |
//写入到编辑器
//Response.Write("<script type="text/javascript">parent.document.KindEditorForm.document.body.innerHTML+='<a href="" + filepath + "" + filepathdate + "/" + photoName2 + "" title=点击放大 target=_blank><img onmousewheel="return imgzoom_b_s(this);" alt=CTRL+鼠标滚轮放大或缩小 src="" + filepath + "" + filepathdate + "/" + photoName2 + "" onload="return imgzoom(this,480)" border=0></a><br><br>';</script>"); 这里是我自己的新闻系统中批量上传文件时用的,加个超链接可以点击放大图片。 |
回复 |