主题: .net 版的上传代码,附一个问题。
作者: sparks345, 发布日期: 2007-01-30 12:19:28, 浏览数: 8247
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;

namespace Web.Editor.upload_cgi
{
/// <summary>
/// SPC345_CGI 的摘要说明。
/// </summary>
public class SPC345_CGI : System.Web.UI.Page
{

private HttpFileCollection Files ;
HttpPostedFile File;
string FileName;
string FileExtension;

//文件保存目录路径
string SavePath = "../attached/";

//文件保存目录URL
string SaveUrl = "./attached/";

//定义允许上传的文件扩展名
string[] ExtArr = new string[] {
".gif"
, ".jpg"
, ".png"
, ".bmp"
};

//最大文件大小
int MaxSize = 1000000;

string Msg1 = "上传文件大小超过限制。";
string Msg2 = "上传文件扩展名是不允许的扩展名。";
string Msg3 = "上传文件失败。";


string FilePath ;
string FileUrl ;

string FileWidth = null;
string FileHeight = null;
string FileBorder = null;
string FileTitle = null;
string FileAlign = null;
string FileHspace = null;
string FileVspace = null;


//上传到相对地址
//bool AbsolutePath = False;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
//检查权限...省略(~_~!)
if(!Page.IsPostBack)
{
try
{
this.init();


if (FileName!="")
{
if (this.CheckExtension(FileExtension))
{
if (File.ContentLength>this.MaxSize)
{
this.Alert(this.Msg1);
}
else
{
if(this.doUploadImg(this.File, Server.MapPath(this.FilePath)))
{
this.UploadSuccess();
}
else
{
throw new Exception(this.Msg3);
}
}
}
else
{
this.Alert(this.Msg2);
}
}
//this.Image1.ImageUrl = File.FileName;
//Response.Write(file.FileName);
}
catch(Exception ex)
{
this.Alert(ex.Message);
}
}
}

private void init()
{
Files = System.Web.HttpContext.Current.Request.Files;
File = Files[0];
//FileName = System.IO.Path.GetFileName(File.FileName);
FileExtension = System.IO.Path.GetExtension(File.FileName);

FileName = Request.Form["fileName"];
FileWidth = Request.Form["imgWidth"];
FileHeight = Request.Form["imgHeight"];
FileBorder = Request.Form["imgBorder"];
FileTitle = Request.Form["imgTitle"];
FileAlign = Request.Form["imgAlign"];
FileHspace = Request.Form["imgHspace"];
FileVspace = Request.Form["imgVspace"];

FilePath = SavePath + FileName;
FileUrl = SaveUrl + FileName;

}

private bool CheckExtension(string extension)
{
bool result=false;
try
{
for(int i=0;i<this.ExtArr.Length;i++)
{
if (extension==this.ExtArr[i])
{
result = true;
break;
}
}
}
catch
{}
return result;
}
private bool doUploadImg(HttpPostedFile f, string path)
{
bool result = false;
try
{
f.SaveAs(path);

result = true;

}
catch(Exception ex){}
return result;
}

//提示,关闭层
private void Alert(string msg)
{
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(""+msg +"");parent.KindDisableMenu();parent.KindReloadIframe();</script>");
Response.Write ("</body>");
Response.Write ("</html>");
}

private void UploadSuccess()
{
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">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
}
}

//-------------------------------------FIN-----------


问题:
添加内容的时候常常会出现:

<p>内容</div>

这样的标签,虽然效果上没有什么大问题,就是感觉心理有点毛,不知道有没有其他什么用意。我看了一下KindEditor.js,有个 KindHtmlToXhtml(str) 函数,第一行内容是这样的:

str = str.replace(/<p(s+)(.*?>)/gi, "<div");

我改成了
str = str.replace(/<p(s*)(.*?>)/gi, "<div");



期待老大ing......
作者: Roddy, 发布日期: 2007-01-30 16:39:37
谢谢支持。
这个问题我也发现了,现在演示里去掉了DIV to P的转换,没有必要这么处理。

http://www.kindsoft.net/editor/KindEditor.js
回复
作者: sparks345, 发布日期: 2007-01-31 12:10:11
thanks~~
回复
发表新帖 发表回复