主题: VS2003+KE,上传图片成功,最后的在KE里写图代码报错。急求。 |
作者: 阿全, 发布日期: 2010-03-15 17:57:48, 浏览数: 7358 |
VS2003+KE,上传图片成功,最后的在KE里写图代码报错。急求。
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; using System.Web.Security; using System.Globalization; namespace Web.editor.php { /// <summary> /// Upload 的摘要说明。 /// </summary> public class Upload : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e) { //文件保存目录路径 string SavePath = "/Upload_Images/"; //文件保存目录URL string SaveUrl = "/Upload_Images/"; //上传图片类型 string[] ExtStr=new string[4]; ExtStr[0] = ".gif"; ExtStr[1] = ".jpg"; ExtStr[2] = ".png"; ExtStr[3] = ".bmp"; //图片的最大大小 int MaxSize = 100000; //错误提示 string[] MsgStr = new string[3]; MsgStr[0] = "上传文件大小超过限制."; MsgStr[1] = "上传文件扩展名是不允许的扩展名."; MsgStr[2] = "上传文件失败\\n请重试."; 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"]; HttpPostedFile imgFile = HttpContext.Current.Request.Files["imgFile"]; //获得文件名 string FileName = System.IO.Path.GetFileName(imgFile.FileName); if (FileName != "") { if (imgFile.ContentLength > MaxSize) { Alert(MsgStr[0]); } else { string fileExtension = System.IO.Path.GetExtension(FileName).ToLower(); if (CheckExt(ExtStr, fileExtension)) { //重新为文件命名,时间毫秒部分+扩展名 string imgReName = "" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-ffff", DateTimeFormatInfo.InvariantInfo) + "" + fileExtension; //文件夹名 string imgFolderName=DateTime.Now.ToString("yyyyMMdd",DateTimeFormatInfo.InvariantInfo); try { if (!System.IO.Directory.Exists(@Server.MapPath("" + SavePath + "" +imgFolderName + ""))) { //生成文件完整目录 System.IO.Directory.CreateDirectory(@Server.MapPath("" + SavePath + "" +imgFolderName + "")); } imgFile.SaveAs(@Server.MapPath("" + SavePath + "" + imgFolderName + "/")+imgReName); } catch { Alert(MsgStr[2]); } string imgUrl = SaveUrl + imgFolderName + "/" + imgReName; ReturnImg(imgUrl, imgWidth, imgHeight, imgBorder, imgTitle, imgAlign, imgHspace, imgVspace); } else { Alert(MsgStr[1]); } } } } /// <summary> /// 提示关闭层 /// </summary> /// <param name="MsgStr"></param> private void Alert(string MsgStr) { Response.Write("<html>"); Response.Write("<head>"); Response.Write("<title>error</title>"); Response.Write("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">"); Response.Write("</head>"); Response.Write("<body>"); Response.Write("<script type=\"text/javascript\">alert(\"" + MsgStr + "\");parent.KindDisableMenu();parent.KindReloadIframe();</script>"); Response.Write("</body>"); Response.Write("</html>"); } /// <summary> /// 检测文件类型 /// </summary> /// <param name="ExtStr"></param> /// <param name="fileExt"></param> /// <returns></returns> private bool CheckExt(string[] ExtStr,string fileExt) { for (int i = 0; i < ExtStr.Length; i++) { if (ExtStr[i] != fileExt) { return true; } } return false; } /// <summary> /// 返回图片 /// </summary> /// <param name="FileUrl"></param> /// <param name="FileWidth"></param> /// <param name="FileHeight"></param> /// <param name="FileBorder"></param> /// <param name="FileTitle"></param> /// <param name="FileAlign"></param> /// <param name="FileHspace"></param> /// <param name="FileVspace"></param> private void ReturnImg( string FileUrl,string FileWidth,string FileHeight,string FileBorder,string FileTitle,string FileAlign,string FileHspace,string FileVspace) { Response.Write("<html>"); Response.Write("<head>"); Response.Write("<title>上传成功</title>"); Response.Write("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">"); Response.Write("</head>"); Response.Write("<body>"); Response.Write("<script type=\"text/javascript\">parent.KindInsertImage(\"" + FileUrl +"\",\"" + FileWidth + "\",\"" + FileHeight + "\",\"" + FileBorder + "\",\"" + FileTitle + "\",\"" + FileAlign + "\",\"" + FileHspace + "\",\"" + FileVspace + "\");</script>"); Response.Write("</body>"); Response.Write("</html>"); } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } } 就是在提示 上传成功的时候,不提示,报错。parent.KindInsertImage 没这个方法。 此页产生了一个脚本错误 Line:1 Char:1 Code:0 Error:'KE' 未定义 网址:http://localhost:203/editor/php/Upload.aspx |