Ajaxfileupload File Upload

Source: Internet
Author: User
Tags button type httpcontext

First quoted Ajaxfileupload.js did not go to csdn under their own

Next is the HTML


<input type= "file" id= "file1" name= "file" style= "Display:none" accept= "Image/x-png,image/gif,image/jpeg, Image/bmp "multiple=" multiple "/><button type= "button" class= "btn btn-info" id= "Btnfile" ><i class= "fa fa-cloud-upload" >&nbsp; upload </i></button>

which accept can specify the upload format multiple= "Multiple" This property allows for multiple file selection

JS section

$ ("#btnFile"). Click (function () {$ ("#file1"). Click ();        }) $ ("#file1"). Change (function () {if ($ ("#file1"). Val (). length > 0) {ajaxfileupload (); } else {Swal ({title: ' Please choose to upload the file!        ', Text: ', type: ' Info '}); }    });

 function ajaxfileupload () {        $.ajaxfileupload        (    &N Bsp       {                URL: '/financialreimbursement/financialreimb Ursement/upload ',//server-side request address for file upload                 type: ' Post ',    &NBS P           data: {Id: ' 123 ', Name: ' Add '},//This parameter is very rigorous, a wrong quote is not possible                 Secureuri:false,//Whether a security protocol is required, generally set to false                Filee Lementid: ' file1 ',//File upload domain id                DataType: ' json ',//return value type generally set to JSON&N Bsp               success:function (data, status)  //Server Success Response processing function                 {                    &N alert ("Upload success"); Bsp            },                error:function (data , status, E)//server response failure handling function                 {          &NBSP ;         alert (e);               }           }       )

Background section

Public ActionResult Upload () {NameValueCollection NVC = System.Web.HttpContext.Current.Request.Form;

String type = NVC. Get ("name");//Get Parameters

Httpfilecollection HFC = System.Web.HttpContext.Current.Request.Files;

  if (HFC. Count > 0)             {                #region & nbsp; perform multiple file uploads                 for (int i = 0; i < HFC. Count; i++)                 {                &NBSP ;   var Filenamearr = Hfc[i]. Filename.split ('. ');                                  &NBS P     String FileName = DateTime.Now.ToString ("YYYYMMDDHHMMSS") + "_" + filenamearr[0] + "." + Filenamearr[1];&nbs P                   Imgpath + = "/allfileup/fortheattachment/" + FileName + ",";                     String IMGP = "/allfileup/fortheattachment/" + filen ame;                    string PhysicalpAth = Server.MapPath (IMGP);                  &NBSP;IF (! Directory.Exists (Server.MapPath ("/allfileup/fortheattachment"))///Storage path folder does not exist on auto new                    {                      &NB Sp;directory. CreateDirectory (Server.MapPath ("/allfileup/fortheattachment"));                   }                    Hfc[i]. SaveAs (PhysicalPath);                                }&NBS P               #endregion             }

Return Json (New {count = HFC. Count});//Returns the number of saved files

}

Write a very messy first write a little bit of format is not hahaha

Ajaxfileupload File Upload

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.