KindEditor是一个不错的网页在线编辑器
可是它只提供了asp
php
jsp上传的类
没有提供上传的类
using System;
using SystemGlobalization;
using SystemCollections;
using SystemConfiguration;
using SystemData;
using SystemWeb;
using SystemWebSecurity;
using SystemWebUI;
using SystemWebUIHtmlControls;
using SystemWebUIWebControls;
using SystemWebUIWebControlsWebParts;
public partial class Jscript_KindEditor_upload_cgi_upload : SystemWebUIPage
{
protected void Page_Load(object sender EventArgs e)
{
//文件保存目录路径
string SavePath = /Upload_Images/;
//文件保存目录URL
string SaveUrl = /Upload_Images/;
//上传图片类型
string[] ExtStr=new string[];
ExtStr[] = gif;
ExtStr[] = jpg;
ExtStr[] = png;
ExtStr[] = bmp;
//图片的最大大小
int MaxSize = ;
//错误提示
string[] MsgStr = new string[];
MsgStr[] = 上传文件大小超过限制;
MsgStr[] = 上传文件扩展名是不允许的扩展名;
MsgStr[] = 上传文件失败\\n请重试;
string imgWidth = RequestForm[imgWidth];
string imgHeight = RequestForm[imgHeight];
string imgBorder = RequestForm[imgBorder];
string imgTitle = RequestForm[imgTitle];
string imgAlign = RequestForm[imgAlign];
string imgHspace = RequestForm[imgHspace];
string imgVspace = RequestForm[imgVspace];
HttpPostedFile imgFile = HttpContextCurrentRequestFiles[imgFile];
//获得文件名
string FileName = SystemIOPathGetFileName(imgFileFileName);
if (FileName != )
{
if (imgFileContentLength > MaxSize)
{
Alert(MsgStr[]);
}
else
{
string fileExtension = SystemIOPathGetExtension(FileName)ToLower();
if (CheckExt(ExtStr fileExtension))
{
//重新为文件命名时间毫秒部分+扩展名
string imgReName = + DateTimeNowToString(yyyyMMddHHmmssffff DateTimeFormatInfoInvariantInfo) + + fileExtension;
//文件夹名
string imgFolderName=DateTimeNowToString(yyyyMMddDateTimeFormatInfoInvariantInfo);
try
{
if (!SystemIODirectoryExists(@ServerMapPath( + SavePath + +imgFolderName + )))
{
//生成文件完整目录
SystemIODirectoryCreateDirectory(@ServerMapPath( + SavePath + +imgFolderName + ));
}
imgFileSaveAs(@ServerMapPath( + SavePath + + imgFolderName + /)+imgReName);
}
catch
{
Alert(MsgStr[]);
}
string imgUrl = SaveUrl + imgFolderName + / + imgReName;
ReturnImg(imgUrl imgWidth imgHeight imgBorder imgTitle imgAlign imgHspace imgVspace);
}
else
{
Alert(MsgStr[]);
}
}
}
}
/// <summary>
/// 提示关闭层
/// </summary>
/// <param name=MsgStr></param>
private void Alert(string MsgStr)
{
ResponseWrite(<html>);
ResponseWrite(<head>);
ResponseWrite(<title>error</title>);
ResponseWrite(<meta httpequiv=\contenttype\ content=\text/html; charset=utf\>);
ResponseWrite(</head>);
ResponseWrite(<body>);
ResponseWrite(<script type=\text/javascript\>alert(\ + MsgStr + \);parentKindDisableMenu();parentKindReloadIframe();</script>);
ResponseWrite(</body>);
ResponseWrite(</html>);
}
/// <summary>
/// 检测文件类型
/// </summary>
/// <param name=ExtStr></param>
/// <param name=fileExt></param>
/// <returns></returns>
private bool CheckExt(string[] ExtStrstring fileExt)
{
for (int i = ; i < ExtStrLength; 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 FileUrlstring FileWidthstring FileHeightstring FileBorderstring FileTitlestring FileAlignstring FileHspacestring FileVspace)
{
ResponseWrite(<html>);
ResponseWrite(<head>);
ResponseWrite(<title>上传成功</title>);
ResponseWrite(<meta httpequiv=\contenttype\ content=\text/html; charset=utf\>);
ResponseWrite(</head>);
ResponseWrite(<body>);
ResponseWrite(<script type=\text/javascript\>parentKindInsertImage(\ + FileUrl +\\ + FileWidth + \\ + FileHeight + \\ + FileBorder + \\ + FileTitle + \\ + FileAlign + \\ + FileHspace + \\ + FileVspace + \);</script>);
ResponseWrite(</body>);
ResponseWrite(</html>);
}
}