国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

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

2024-07-10 12:44:24
字體:
來源:轉載
供稿:網友

代碼如下:
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>");

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 静海县| 固阳县| 蓝田县| 新宾| 交城县| 讷河市| 京山县| 仲巴县| 湛江市| 丰顺县| 九江市| 西宁市| 涪陵区| 乳山市| 康平县| 田林县| 望谟县| 乌鲁木齐县| 神木县| 涞水县| 利津县| 南召县| 广水市| 清镇市| 正定县| 金阳县| 马山县| 高安市| 彰武县| 吴堡县| 东阿县| 轮台县| 垦利县| 龙里县| 长垣县| 民勤县| 图木舒克市| 钟祥市| 瑞昌市| 龙山县| 淮滨县|