您好,欢迎来到零搜情感。
搜索
您的当前位置:首页基于jQuery通过jQuery.form.js插件实现异步上传_jquery

基于jQuery通过jQuery.form.js插件实现异步上传_jquery

来源:零搜情感


本文主要从前台和后台代码分析了jquery.form.js实现异步上传的方法,分享给大家,具体代码如下

前台代码:

@{
 Layout = null;
}



 
 
 
 upload


 

 
 
 

 
 

后台代码:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace IceMvc.Controllers
{
 public class UploadController : Controller
 {
 //
 // GET: /Upload/

 public ActionResult Index()
 {
 return View();
 }

 [HttpPost]
 public ActionResult Upload()
 {
 var filesList = Request.Files;
 for (int i = 0; i < filesList.Count; i++)
 {
 var file = filesList[i];
 if (file.ContentLength > 0)
 {
 if (file.ContentLength > 5242880)
 {
 return Content("alert('注册失败!因为您选择图片文件不能大于5M.');window.location='/User/Register';");
 }

 //得到原图的后缀
 string extName = System.IO.Path.GetExtension(file.FileName);
 //生成新的名称
 string newName = Guid.NewGuid() + extName;

 string imgPath = Server.MapPath("/upload/img/") + newName;

 if (file.ContentType.Contains("image/"))
 {
 using (Image img = Image.FromStream(file.InputStream))
 {
 img.Save(imgPath);
 }
 var obj = new { fileName = newName };
 return Json(obj);
 }
 else
 {
 //return Content("

Copyright © 2019- 0shou.net 版权所有

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务