Kindeditor picture Upload asp.net code example _ practical skills

Source: Internet
Author: User

Copy Code code 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 picture type
String[] Extstr=new string[4];
Extstr[0] = ". gif";
EXTSTR[1] = ". jpg";
EXTSTR[2] = ". png";
EXTSTR[3] = ". bmp";
Maximum size of picture
int MaxSize = 100000;
Error tips
string[] Msgstr = new String[3];
Msgstr[0] = "Upload file size exceeds limit."
MSGSTR[1] = "Upload file name extension is not allowed extension.";
MSGSTR[2] = "Upload file failed//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 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 file again, 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 + "))
{
Build file Complete Directory
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>
Tip Close Layer
</summary>
<param name= "Msgstr" ></param>
private void Alert (string msgstr)
{
Response.Write ("Response.Write ("Response.Write ("<title>error</title>");
Response.Write ("<meta http-equiv=/" content-type/"content=/" text/html; charset=utf-8/">");
Response.Write ("Response.Write ("<body>");
Response.Write ("<script type=/" text/javascript/">alert (/" + Msgstr + "/");p arent. Kinddisablemenu ();p arent. Kindreloadiframe ();</script> ");
Response.Write ("</body>");
Response.Write ("}
<summary>
Detecting file types
</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>
Back to Picture
</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 ("Response.Write ("Response.Write ("<title> upload success </title>");
Response.Write ("<meta http-equiv=/" content-type/"content=/" text/html; charset=utf-8/">");
Response.Write ("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 ("}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.