swfupload组件上传文件
前段时间做文件上传用的是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组件上传文件的更多相关文章
- 使用commons-fileUpload组件上传文件
在近期的一个项目中有用到commons-fileUpload组件进行实现文件上传的功能(由于没用到框架),在使用的过程中有遇到一些问题,经过自己的琢磨也算顺利地将其解决了,在这里做个记录. 一.com ...
- EasyUI 关于IE使用window组件上传文件
有时候IE会对使用window组件上传文件(第二次)不生效,解决方案是: 将该window每次打开的时候,使用: $('#adUploadWindow').window('refresh', 'pan ...
- 关于commons-fileupload组件上传文件中文名乱码问题
java web开发,常用到的文件上传功能,常用的commons-fileupload和commons-io两个jar包.关于如何使用这两个jar来完成文件上传的功能,这里不做详解.使用commons ...
- 在Struts2中使用Uploadify组件上传文件
Uploadify是一个基于Jquery的文件上传组件,官网http://www.uploadify.com/可以在官网获得该组件,运行演示示例,下载帮助文档. 作为Web前端的增强技术,Jq ...
- javaweb-番外篇-Commons-FileUpload组件上传文件
一.Commons-FileUpload简介 Commons-FileUpload组件 Commons是Apache开放源代码组织的一个Java子项目,其中的FileUpload是用来处理HTTP文件 ...
- django Form组件 上传文件
上传文件 注意:FORM表单提交文件要有一个参数enctype="multipart/form-data" 普通上传: urls: url(r'^f1/',views.f1), u ...
- Ant Design Upload 组件上传文件到云服务器 - 七牛云、腾讯云和阿里云的分别实现
在前端项目中经常遇到上传文件的需求,ant design 作为 react 的前端框架,提供的 upload 组件为上传文件提供了很大的方便,官方提供的各种形式的上传基本上可以覆盖大多数的场景,但是对 ...
- [插件] 如何在一个页面中使用多个SWFUpload对象上传文件
首先需要引入相应的样式和JS文件,还需要借助jQuery的js 提供下载路径:http://pan.baidu.com/s/1EUzca ① 引入js <script type="te ...
- VUE -- 用组件上传文件和用xmlrequest上传
xmlrequest: sendForm(str, types) { var form = this.$refs.ipas_form; var oOutput = document.querySele ...
随机推荐
- 搞不懂的算法-排序篇<2>
上一篇排序算法<1>中,排序算法的时间复杂度从N2到NlgN变化,但他们都有一个共同的特点,基于比较和交换数组中的元素来实现排序,我们称这些排序算法为比较排序算法.对于比较排序算法,所有的 ...
- VFS文件系统结构分析 与socket
本文乃fireaxe原创,使用GPL发布,可以自由拷贝,转载.但转载请保持文档的完整性,并注明原作者及原链接.内容可任意使用,但对因使用该内容引起的后果不做任何保证. 作者:fireaxe_hq@ho ...
- PhotoZoom控制面板简介说明
PhotoZoom是一款极其简单的图片无损放大工具,简单几步渲染出完美的放大照片,呈现无与伦比的画质效果.即可虽然简单,菜单和面板的功能很少,但却是设计师的必备神器,因为其简单易用性,它的软件菜单命令 ...
- python编写简单的html登陆页面(4)
python编写简单的html登陆页面(4) 1 在python编写简单的html登陆页面(2)的基础上在延伸一下: 可以将动态态分配数据,建立表格,存放学生信息 2 实现的效果如下: 3 动 ...
- win7/win10 未分配磁盘怎样创建扩展分区 也就是逻辑分区(转截)
我们有时候用windows7的磁盘管理工具对windows7系统分区管理的时候,我们可能会不小心把我们的电脑硬盘扩展分区都删除了,扩展分区变为了未分配的空间,这时候如果我们新建分区的话,建立的都是主分 ...
- Javaee 方法的构建和调用
主类: package Szy02; public class Person { String name; int age; String sex; public Person(){ } public ...
- 路飞学城Python-Day137
django项目二 个人博客系统 github地址:https://github.com/pandaboy1123/cnblog
- RobotFrameWork+APPIUM实现对安卓APK的自动化测试----第三篇【实例】
http://blog.csdn.net/deadgrape/article/details/50579565 在这一篇里我先让大家看一下RF+APPIUM这个框架的实际运行时什么样子的,给大家一个直 ...
- HDU 2439 The Mussels
The Mussels Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID ...
- 洛谷 U5737 纸条
U5737 纸条 题目背景 明明和牛牛是一对要好的朋友,他们经常上课也想讲话,但是他们的班级是全校纪律最好的班级,所以他们只能通过传纸条的方法来沟通.但是他们并不能保证每次传纸条老师都无法看见,所以他 ...