Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the Asp.net code for uploading KindEditor pictures

Shulou Source: shulou.com Published: 2022-06-03 07:40:24 09月19日 Update

This article introduces the relevant knowledge of "how to upload Asp.net code for KindEditor pictures". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The copy code is as follows:

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)

{

/ / File save directory path

String SavePath = "/ Upload_Images/"

/ / File save directory URL

String SaveUrl = "/ Upload_Images/"

/ / upload image type

String [] ExtStr=new string [4]

ExtStr [0] = ".gif"

ExtStr [1] = ".jpg"

ExtStr [2] = ".png"

ExtStr [3] = ".bmp"

/ / the maximum size of the image

Int MaxSize = 100000

/ / error prompt

String [] MsgStr = new string [3]

MsgStr [0] = "upload file size exceeds limit."

MsgStr [1] = "upload file extension is not allowed."

MsgStr [2] = "failed to upload file / / n Please try again."

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"]

/ / get the file name

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))

{

/ / rename the file, time millisecond part + extension

String imgReName = "" + DateTime.Now.ToString ("yyyy-MM-dd-HH-mm-ss-ffff", DateTimeFormatInfo.InvariantInfo) + "" + fileExtension

/ / folder name

String imgFolderName=DateTime.Now.ToString ("yyyyMMdd", DateTimeFormatInfo.InvariantInfo)

Try

{

If (! System.IO.Directory.Exists (@ Server.MapPath ("" + SavePath + "+ imgFolderName +")

{

/ / complete directory of generated files

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])

}

}

}

}

/ / /

/ / prompt to close the layer

/ / /

/ / /

Private void Alert (string MsgStr)

{

Response.Write ("")

Response.Write ("")

Response.Write ("error")

Response.Write ("")

Response.Write ("")

Response.Write ("")

Response.Write ("alert (/"+ MsgStr +" / "); parent.KindDisableMenu (); parent.KindReloadIframe ();")

Response.Write ("")

Response.Write ("")

}

/ / /

/ / detect the file type

/ / /

/ / /

/ / /

/ / /

Private bool CheckExt (string [] ExtStr,string fileExt)

{

For (int I = 0; I < ExtStr.Length; iTunes +)

{

If (ExtStr [I]! = fileExt)

{

Return true

}

}

Return false

}

/ / /

/ / return the picture

/ / /

/ / /

/ / /

/ / /

/ / /

/ / /

/ / /

/ / /

/ / /

Private void ReturnImg (string FileUrl,string FileWidth,string FileHeight,string FileBorder,string FileTitle,string FileAlign,string FileHspace,string FileVspace)

{

Response.Write ("")

Response.Write ("")

Response.Write ("upload successful")

Response.Write ("")

Response.Write ("")

Response.Write ("")

Response.Write ("parent.KindInsertImage (/"+ FileUrl +" / ", /" + FileWidth + "/", / "" + FileHeight + "/", / "+ FileBorder +" / ", /" + FileTitle + "/", / "+ FileAlign +" / ", /"+ FileHspace +" / ", /"+ FileVspace +" / ");")

Response.Write ("")

Response.Write ("")

}

}

This is the end of the content of "how to upload Asp.net code for KindEditor images". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: File picture code extension directory content size more knowledge type hint utility maximum success achievement next dilemma reality situation file name Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info OPPO Reno Shulou Technology Redmi vpn