主頁 > 知識庫 > KindEditor圖片上傳的Asp.net代碼實例

KindEditor圖片上傳的Asp.net代碼實例

熱門標簽:怎樣給陜西地圖標注顏色 400電話辦理信任翰諾科技 福州人工智能電銷機器人加盟 云狐人工智能電話機器人 ai電銷機器人對貸款有幫助嗎 宿遷智能外呼系統(tǒng)排名 電銷機器人 數(shù)據(jù) 地圖標注多少錢一張 廣州銷售外呼系統(tǒng)定制

復(fù)制代碼 代碼如下:

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>
/// 提示關(guān)閉層
/// /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單獨調(diào)用單圖上傳增加預(yù)覽功能的實例
  • Kindeditor單獨調(diào)用多圖上傳實例
  • node.js中實現(xiàn)kindEditor圖片上傳功能的方法教程
  • asp.net core集成kindeditor實現(xiàn)圖片上傳功能
  • js控件Kindeditor實現(xiàn)圖片自動上傳功能
  • nodejs 整合kindEditor實現(xiàn)圖片上傳
  • springmvc+kindeditor文件上傳實例詳解

標簽:焦作 綿陽 新疆 宜春 黃南 曲靖 大興安嶺 延安

巨人網(wǎng)絡(luò)通訊聲明:本文標題《KindEditor圖片上傳的Asp.net代碼實例》,本文關(guān)鍵詞  KindEditor,圖片,上傳,的,Asp.net,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《KindEditor圖片上傳的Asp.net代碼實例》相關(guān)的同類信息!
  • 本頁收集關(guān)于KindEditor圖片上傳的Asp.net代碼實例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章