日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Kindeditor图片上传Controller

發布時間:2024/9/5 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Kindeditor图片上传Controller 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

asp.net MVC?Kindeditor 圖片、文件上傳所用的Controller

1 [HttpPost, AllowAnonymous] 2 public ActionResult UploadImage() 3 { 4 string savePath = VirtualPaths.ImgDir + "/Upload/"; 5 string saveUrl = "/Upload/"; 6 string fileTypes = "gif,jpg,jpeg,png,bmp"; 7 int maxSize = 1000000; 8 9 var hash = new Hashtable(); 10 11 HttpPostedFileBase file = Request.Files["imgFile"]; 12 if (file == null) 13 { 14 hash = new Hashtable(); 15 hash["error"] = 1; 16 hash["message"] = "請選擇文件"; 17 return Json(hash, "text/html;charset=UTF-8"); 18 } 19 20 string dirPath = savePath; 21 if (!Directory.Exists(dirPath)) 22 { 23 Directory.CreateDirectory(dirPath); 24 } 25 26 string fileName = file.FileName; 27 string fileExt = Path.GetExtension(fileName).ToLower(); 28 29 ArrayList fileTypeList = ArrayList.Adapter(fileTypes.Split(',')); 30 31 if (file.InputStream == null || file.InputStream.Length > maxSize) 32 { 33 hash = new Hashtable(); 34 hash["error"] = 1; 35 hash["message"] = "上傳文件大小超過限制"; 36 return Json(hash, "text/html;charset=UTF-8"); 37 } 38 39 if (string.IsNullOrEmpty(fileExt) || 40 Array.IndexOf(fileTypes.Split(','), fileExt.Substring(1).ToLower()) == -1) 41 { 42 hash = new Hashtable(); 43 hash["error"] = 1; 44 hash["message"] = "上傳文件擴展名是不允許的擴展名"; 45 return Json(hash, "text/html;charset=UTF-8"); 46 } 47 48 string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + 49 fileExt; 50 string filePath = dirPath + newFileName; 51 file.SaveAs(filePath); 52 string fileUrl = saveUrl + newFileName; 53 54 hash = new Hashtable(); 55 hash["error"] = 0; 56 hash["url"] = fileUrl; 57 58 return Json(hash, "text/html;charset=UTF-8"); 59 }

?

轉載于:https://www.cnblogs.com/baiyunchen/p/4010554.html

總結

以上是生活随笔為你收集整理的Kindeditor图片上传Controller的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。