主页 > 知识库 > KindEditor图片上传的Asp.net代码实例

KindEditor图片上传的Asp.net代码实例

热门标签:怎样给陕西地图标注颜色 400电话办理信任翰诺科技 福州人工智能电销机器人加盟 云狐人工智能电话机器人 ai电销机器人对贷款有帮助吗 宿迁智能外呼系统排名 电销机器人 数据 地图标注多少钱一张 广州销售外呼系统定制

复制代码 代码如下:

using System;
using System.Globalization;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
public partial class Jscript_KindEditor_upload_cgi_upload : System.Web.UI.Page
{
protected void Page_Load(object sender, 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>");
}
}

您可能感兴趣的文章:
  • kindeditor 加入七牛云上传的实例讲解
  • Kindeditor编辑器添加图片上传水印功能(php代码)
  • Kindeditor单独调用单图上传增加预览功能的实例
  • Kindeditor单独调用多图上传实例
  • node.js中实现kindEditor图片上传功能的方法教程
  • asp.net core集成kindeditor实现图片上传功能
  • js控件Kindeditor实现图片自动上传功能
  • nodejs 整合kindEditor实现图片上传
  • springmvc+kindeditor文件上传实例详解

标签:焦作 绵阳 新疆 宜春 黄南 曲靖 大兴安岭 延安

巨人网络通讯声明:本文标题《KindEditor图片上传的Asp.net代码实例》,本文关键词  KindEditor,图片,上传,的,Asp.net,;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 下面列出与本文章《KindEditor图片上传的Asp.net代码实例》相关的同类信息!
  • 本页收集关于KindEditor图片上传的Asp.net代码实例的相关信息资讯供网民参考!
  • 推荐文章