下载uploadify文件

http://www.uploadify.com/

HTML(视图)

<html lang="zh-cn">
<head>
<meta content="true">
<meta charset="UTF-8">
<script src="~/Areas/Test/Uploadify/jquery.uploadify.js"></script>
<link href="~/Areas/Test/Uploadify/uploadify.css" rel="stylesheet" />
<title>uploadify多文件上传例子</title>
</head>
<body>
<input type="file" id="file_upload" name="file_upload" />
</body>
</html>

JS

<script>
$(function () {
$('#file_upload').uploadify({
'swf': '@Url.Content("/Areas/Test/Uploadify/uploadify-v3.1/uploadify.swf")',
'uploader': '@Url.Action("UploadAppraisal")?resultPath=Upload',
'auto': true,
'fileTypeExts': '*.*',
'fileTypeDesc':'All Files',
'fileSizeLimit': '',
'buttonText': '添加文件',
'width': ,
'height': ,
'margin-right': ,
multi: false,
queueSizeLimit: ,
timeoutuploadLimit: ,
removeCompleted: true,
uploadLimit: ,
'onSelect': function (file) { },
'onUploadStart' : function(file) { },
'onUploadProgress': function (file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) { },
'onInit': function () { },
'onUploadSuccess': function (file, data, response) { }
});
});</script>

后台(MVC控制器)

public JsonResult UploadAppraisal(HttpPostedFileBase fileData, string resultPath)
{
if (fileData != null)
{
try
{
// 文件上传后的保存路径
string filePath = Server.MapPath("../Upload/temp");
string Size = HumanReadableFilesize(fileData.ContentLength);
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
} string fileNames = Path.GetFileName(fileData.FileName);// 原始文件名称
string fileName = Regex.Match(fileNames, @".*?(?=[.])").Value;//去掉后缀名字的文件名字
string fileExtension = Path.GetExtension(fileNames); // 文件扩展名
string saveName = Guid.NewGuid().ToString() + fileExtension; // 保存文件名称
string path = filePath + "\\" + saveName;
string Filesize = HumanReadableFilesize(fileData.ContentLength);//字节大小
string FileDw = HumanReadableFile(fileData.ContentLength);//字节单位
fileData.SaveAs(path); return Json(new
{ Success = true, FileName = saveName});
}
catch (Exception ex)
{
return Json(new
{ Success = false, Message = ex.Message }, JsonRequestBehavior.AllowGet);
}
}
else
{
return Json(new
{ Success = false, Message = "请选择要上传的文件!" }, JsonRequestBehavior.AllowGet);
}
}

一个页面有多个上传控件

修改jquery.uploadify.js、jquery.uploadify.min.js

   var mydate = new Date();
this.movieName = "SWFUpload_" + mydate.getTime().toString();

上传大文件(Web.config)

Web.config添加一下代码

<system.web>
<compilation debug="true" targetFramework="4.5" />
<!--maxRequestLength就是文件的最大字符数,最大值不能超过2个G左右,executionTimeout是超时时间-->
<httpRuntime targetFramework="4.5" maxRequestLength="" executionTimeout="" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<!--修改服务器允许最大长度-->
<requestLimits maxAllowedContentLength=""/>
</requestFiltering>
</security>
</system.webServer>

最新文章

  1. 理解 JavaScript 回调函数并使用
  2. 线性控制原理——PID算法应用
  3. set和map和pair 转自ACdreamers
  4. win7 去除桌面快捷方式小箭头
  5. go实现选择排序
  6. Cs231n-assignment 1作业笔记
  7. 动态规划 - 213. House Robber II
  8. 全志A33 linux led驱动编程(附实测参考代码)
  9. android AIDL 语言用法
  10. 二、LINQ之查询表达式基础
  11. hyper-v NAT网络
  12. 如何判断Android设备是否为模拟器
  13. 以OPC PowerTool 连接iFix与KEPWARE
  14. 【java规则引擎】《Drools7.0.0.Final规则引擎教程》第4章 4.4 LHS简介&amp;Pattern
  15. Android解析WindowManager(三)Window的添加过程
  16. python抠图与pip install PIL报错
  17. 谈对“Git”的认识与理解
  18. Android网络开发之HttpURLConnection
  19. IIS6 伪静态 IIS文件类型映射配置方法 【图解】
  20. win64 Python下安装PIL出错解决2.7版本 (3.6版本可以使用)

热门文章

  1. spring通知执行的顺序
  2. ConcurrentHashMap1.8源码分析
  3. spring boot拦截器中获取request post请求中的参数
  4. Java:配置环境(Mac)——Eclipse;修改JDK版本后,Eclipse打不开
  5. matplotlib正弦和余弦图
  6. gcc/g++ 编译参数
  7. [转]Lua和Lua JIT及优化指南
  8. 【学习记录】第一章 数据库设计-《SQL Server数据库设计和开发基础篇视频课程》
  9. node编写定时任务,for循环只执行一遍的解决办法
  10. 为什么要花钱学 Python,自学不好吗?