本文实例为大家分享了swupload实现多图片上传的具体代码,供大家参考,具体内容如下
1. 下载WebUploader
2. 将下载到的压缩包里面的文件复制到自己的项目中
3. 添加引用
4.准备一个放图片的容器和一个上传按钮
5.创建Web Uploader实例并监听事件
6 在Controller里新建一个Action用于保存图片并返回图片路径(这方法是 eflay 前辈博客上说的)
public ActionResult UpLoadProcess(string id, string name, string type, string lastModifiedDate, int size, HttpPostedFilebase file)
{
string filePathName = string.Empty;
string localPath = Path.Combine(HttpRuntime.AppDomainAppPath, "Upload");
if (Request.Files.Count == 0)
{
return Json(new { jsonrpc = 2.0, error = new { code = 102, message = "保存失败" }, id = "id" });
}
string ex = Path.GetExtension(file.FileName);
filePathName = Guid.NewGuid().ToString("N") + ex;
if (!System.IO.Directory.Exists(localPath))
{
System.IO.Directory.CreateDirectory(localPath);
}
file.SaveAs(Path.Combine(localPath, filePathName));
return Json(new
{
jsonrpc = "2.0",
id = id,
filePath = "/Upload/" + filePathName
});
}
这样就大功告成了。
由于是第一次写博客,里面如果有写的不详细或不对的地方,欢迎大家指点。希望能和大家一起进步。
源码下载:swupload实现多图片上传
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



