Fine Uploader 是一个采用Ajax技术实现的文件上传组件,支持拖拽文件上传。使用很简便,只需在页面中引入相应的CSS+Javascrip{过滤}t,剩下的就只服务器端处理逻辑。在其提供的下载包中已经有多种语言实现包括:ASP.NET, ColdFusion, Java, Node.js, Perl, PHP, Python 。
前台:
- <div id="fine-uploader"></div>
复制代码 js:
- $(function () {
- $('#fine-uploader').fineUploader({
- request: {
- endpoint: '/Upload/ProcessUpload'
- },
- validation: {
- allowedExtensions: ['jpeg', 'jpg', 'png'],
- sizeLimit: 2097152
- },
- multiple: false,
- text: {
- uploadButton: '<div>上传头像</div>',
- dropProcessing: "(支持文件拖放上传,只能上传单张2M以下png、jpg、gif图片)"
- }
- }).on('complete', function (event, id, fileName, responseJson) {
- if (responseJson.success) {
-
- //这里是上传成功之后的东西
- }
- });
-
- });
复制代码 后台代码:
- [HttpPost]
- public ActionResult ProcessUpload(string qqfile)
- {
- try
- {
- string uploadFolder = "/Images/Temp/";
- string imgName = Guid.NewGuid().ToString("D");
- string imgType = Path.GetExtension(qqfile);
- string uploadPath = Server.MapPath(uploadFolder);
- if (!Directory.Exists(uploadPath))
- {
- Directory.CreateDirectory(uploadPath);
- }
- using (var inputStream = Request.InputStream)
- {
- using (var flieStream = new FileStream(uploadPath + imgName + imgType, FileMode.Create))
- {
- inputStream.CopyTo(flieStream);
- }
- }
- //获取图片的宽度和高度
- //using (FileStream fs = new FileStream(@"1.jpg", FileMode.Open, FileAccess.Read))
- //{
- // System.Drawing.Image image = System.Drawing.Image.FromStream(fs);
- // string width = image.Width.ToString();
- // string height = image.Height.ToString();
- //}
- return Json(new { success = true, message = uploadFolder + imgName + imgType, width = 852, height =1136});
- }
- catch (Exception ex)
- {
- return Json(new { fail = true, message = "上传失败!" });
- }
- }
复制代码 这个是js压缩包:
fineuploader.rar
(11.47 KB, 下载次数: 0, 售价: 2 粒MB)
|