1.此文章是用原生JS来进行文件的上传,有两个版本,一个不用ajax,一个用ajax。
1)非AJAX
2)AJAX
2. 后台
public ActionResult UploadBusinessImage(HttpPostedFileBase ProductImage) { string error = ""; try { //文件上传 HttpPostedFileBase postFileBase = ProductImage; //文件后缀 string extension = Path.GetExtension(postFileBase.FileName); //文件流 Stream uploadStream = postFileBase.InputStream; //把文件写入到本地E盘 using (var fileStream = System.IO.File.Create("E:\\" + postFileBase.FileName)) { uploadStream.Seek(0, SeekOrigin.Begin); uploadStream.CopyTo(fileStream); } return this.Json(error, JsonRequestBehavior.AllowGet); } catch (Exception e) { return this.Json(e.Message, JsonRequestBehavior.AllowGet); } }
posted on 2016-09-05 22:05 阅读( ...) 评论( ...)