前段时间做文件上传用的是H5的一个插件,由于浏览器的兼容性不好,所以又换了一个Flash版本的上传文件插件,感觉这个上传插件的使用方式跟H5的差不多,有些雷同。不过,由于后续浏览不再支持Flash(略囧),所以,暂时还没有找到能够完美兼容浏览器的上传文件插件。各位网友如果有好的插件,请推荐下。

  View代码:

 <html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Content/swfupload/swfupload.js"></script>
<script src="~/Content/swfupload/handlers.js"></script>
<script type="text/javascript">
var swfu;
window.onload = function () {
swfu = new SWFUpload({
// Backend Settings
upload_url: "/UploadFile/UploadFile",
post_params : {
}, // File Upload Settings
file_size_limit : "2 MB",
file_types : "*.jpg;*.bmp;*.jpg;*.jpeg;*.png;*.gif",
file_types_description : "JPG Images;bmp Images;jpg Images;jpeg Images;png Images;gif Images",
file_upload_limit : , // Zero means unlimited // Event Handler Settings - these functions as defined in Handlers.js
// The handlers are not part of SWFUpload but are part of my website and control how
// my website reacts to the SWFUpload events.
swfupload_preload_handler : preLoad,
swfupload_load_failed_handler : loadFailed,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete, // Button settings
button_image_url: "/Content/swfupload/images/XPButtonNoText_160x22.png",
button_placeholder_id : "spanButtonPlaceholder",
button_width: ,
button_height: ,
button_text : '<span class="button">上传文件<span class="buttonSmall">(2 MB Max)</span></span>',
button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 14pt; } .buttonSmall { font-size: 10pt; }',
button_text_top_padding: ,
button_text_left_padding: , // Flash Settings
flash_url : "/Content/swfupload/swfupload.swf", // Relative to this file
flash9_url: "/Content/swfupload/swfupload_FP9.swf", // Relative to this file custom_settings : {
upload_target : "divFileProgressContainer"
}, // Debug Settings
debug: false
}); //文件上传成功后,给用户提示信息
function uploadSuccess(file, serverData) {
var result = serverData.split('|');
if (result[] == 'ok') {
alert(result[]);
}
}
} </script>
</head>
<body>
<div id="content">
<div id="swfu_container" style="margin: 0px 10px;">
<div>
<span id="spanButtonPlaceholder"></span>
</div>
<div id="divFileProgressContainer" style="height: 75px;"></div>
<div id="thumbnails"></div>
</div>
</div>
</body>
</html>

Controller代码:

 private string uploadPath = ConfigurationManager.AppSettings["UploadFile"];//文件上传路径
private string fileFormat = ConfigurationManager.AppSettings["FileFormat"];//允许上传的文件格式 /// <summary>
/// 保存上传文件
/// </summary
/// <returns></returns>
public ActionResult UploadFile()
{
HttpPostedFileBase fileData = Request.Files["Filedata"];
string fileExt = Path.GetExtension(fileData.FileName); string[] formatArray = fileFormat.Split('|');
if (!formatArray.Contains(fileExt)) //前端有格式的限制,但我觉得安全起见,后端还是验证下好点
{
return Content("no|上传文件格式不正确");
}
string saveDirectory = uploadPath + "/UploadFile/";//保存上传文件的文件夹
if (!Directory.Exists(saveDirectory))
{
Directory.CreateDirectory(saveDirectory);
} string fileName = Guid.NewGuid().ToString() + fileExt;
string savePath = saveDirectory + fileName;
fileData.SaveAs(savePath);//上传文件保存 return Content("ok|文件上传成功");
}

webconfig中的配置

 <add key="UploadFile" value="E:/swfUploadFileStorage/"/>
<add key="FileFormat" value=".bmp|.jpg|.jpeg|.png|.gif"/>

  

swfupload组件上传文件的更多相关文章

  1. 使用commons-fileUpload组件上传文件

    在近期的一个项目中有用到commons-fileUpload组件进行实现文件上传的功能(由于没用到框架),在使用的过程中有遇到一些问题,经过自己的琢磨也算顺利地将其解决了,在这里做个记录. 一.com ...

  2. EasyUI 关于IE使用window组件上传文件

    有时候IE会对使用window组件上传文件(第二次)不生效,解决方案是: 将该window每次打开的时候,使用: $('#adUploadWindow').window('refresh', 'pan ...

  3. 关于commons-fileupload组件上传文件中文名乱码问题

    java web开发,常用到的文件上传功能,常用的commons-fileupload和commons-io两个jar包.关于如何使用这两个jar来完成文件上传的功能,这里不做详解.使用commons ...

  4. 在Struts2中使用Uploadify组件上传文件

    Uploadify是一个基于Jquery的文件上传组件,官网http://www.uploadify.com/可以在官网获得该组件,运行演示示例,下载帮助文档.     作为Web前端的增强技术,Jq ...

  5. javaweb-番外篇-Commons-FileUpload组件上传文件

    一.Commons-FileUpload简介 Commons-FileUpload组件 Commons是Apache开放源代码组织的一个Java子项目,其中的FileUpload是用来处理HTTP文件 ...

  6. django Form组件 上传文件

    上传文件 注意:FORM表单提交文件要有一个参数enctype="multipart/form-data" 普通上传: urls: url(r'^f1/',views.f1), u ...

  7. Ant Design Upload 组件上传文件到云服务器 - 七牛云、腾讯云和阿里云的分别实现

    在前端项目中经常遇到上传文件的需求,ant design 作为 react 的前端框架,提供的 upload 组件为上传文件提供了很大的方便,官方提供的各种形式的上传基本上可以覆盖大多数的场景,但是对 ...

  8. [插件] 如何在一个页面中使用多个SWFUpload对象上传文件

    首先需要引入相应的样式和JS文件,还需要借助jQuery的js 提供下载路径:http://pan.baidu.com/s/1EUzca ① 引入js <script type="te ...

  9. VUE -- 用组件上传文件和用xmlrequest上传

    xmlrequest: sendForm(str, types) { var form = this.$refs.ipas_form; var oOutput = document.querySele ...

随机推荐

  1. 项目随笔之springmvc中freemark如何获取项目路径

    转载:http://blog.csdn.net/whatlookingfor/article/details/51538995 在SpringMVC框架中使用Freemarker试图时,要获取根路径的 ...

  2. Jmeter报内存溢出解决方案

    描述:wimdows环境,做上传图片接口测试,涉及图片合成和上传,图片采用base64编码.每1s启动200线程的时候,Jmeter报内存溢出错误. 解决方案: 1.修改jmeter.bat: set ...

  3. RabbitMQ学习之集群模式

    由于RabbitMQ是用erlang开发的,RabbitMQ完全依赖Erlang的Cluster,因为erlang天生就是一门分布式语言,集群非常方便,但其本身并不支持负载均衡.Erlang的集群中各 ...

  4. C# 把对象序列化 JSON 字符串 和把JSON字符串还原为对象

    /// <summary> /// 把对象序列化 JSON 字符串 /// </summary> /// <typeparam name="T"> ...

  5. 图片无损放大工具PhotoZoom如何进行打印设置

    我们使用PhotoZoom对照片进行无失真放大后,想将照片给打印出来需要设置一些常规参数时.那么这些参数我们该从哪里设置,怎么设置呢? PhotoZoom下载:pan.baidu.com/s/1cXb ...

  6. poj 3669 bfs(这道题隐藏着一个大坑)

    题意 在x,y坐标系,有流星会落下来,给出每颗流星落下来的坐标和时间,问你能否从(0,0)这个点到一个安全的位置.所谓的安全位置就是不会有流星落下的位置. 题解: 广搜,但是这里有一个深坑,就是搜索的 ...

  7. VMware VCSA 6.0安装过程 (转)

    VMware VCSA 6.0安装过程(专版)  一.环境准备   VMware vCenter Server Appliance(VCSA)6.0的部署和之前的版本不同,在5.5及之前的版本可以通过 ...

  8. Eclipse maven工程 Missing artifact com.sun:tools:jar:1.7.0:system 解决方法

    解决方案一:通过maven取运行时参数,eclipse提供的环境变量,基本类似System.getProperty("java.home") <dependency> ...

  9. Python笔记17---------魔法方法

    魔法方法也为特殊方法,即用两个下划线形成的(__方法__).自己定义的方法最好不要采用这种方式,因为这些方法会在一些特殊的情况下直接被调用. 1.第一个魔法方法:类中常用的__init__()方法:相 ...

  10. linux 遇到(vsftpd)—500 OOPS:chroot

    今天在用vsftpd 时出现一个问题: 500 OOPS:chroot 解决办法: 1.关闭SELINUX [root@localhost ~]#vi /etc/sysconfig/selinux # ...