尝试用Uplodify

时间:2021-05-15 14:38:30

尝试用Uplodify

    Uplodify官方

前台index代码:

@{
Layout = null;
} <script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/uploadify/jquery.uploadify.js"></script>
<script src="~/Scripts/uploadify/jquery.uploadify.min.js"></script>
<link href="~/Content/Site.css" rel="stylesheet" />
<link href="~/Content/uploadify.css" rel="stylesheet" /> <script type="text/javascript">
$(function () {
$('#duUpload').uploadify({
//buttonImage: '/Images/makemoney.jpg',
swf: '/Scripts/uploadify/uploadify.swf',
uploader: '@Url.Action("Upload")',
fileTypeExt: '*.jpg; *.png; *.gif',
fileSizeLimit: '100000KB',
buttonText: '预 览',
fileTypeDesc: '图片',
onSelect: function (file) {
}
});
});
</script> <input type="file" name="duUpload" id="duUpload" value="预览" />

后台代码:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc; namespace UploadifyStudy150823.Controllers
{
public class UploadfiyStudyController : Controller
{
public ActionResult Index()
{
return View();
} [HttpPost]
public void Upload(FormCollection fc)
{
string newFileName = string.Empty;
if (Request.Files.Count > )
{
HttpPostedFileBase file = Request.Files[];
string extension = Path.GetExtension(file.FileName);
newFileName = Guid.NewGuid().ToString("N").ToUpper() + extension;
string name = Path.Combine(Server.MapPath("/DuUpload/Images/"), newFileName);
file.SaveAs(name);
}
}
}
}

上传效果图:

尝试用Uplodify

可存进去了?

尝试用Uplodify

是的,存进去了。