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 ...
随机推荐
- JavaScript Math 对象常用方法
Math.abs(x):可返回数的绝对值 Math.ceil(x):向上取整 Math.floor(x):向下取整 Math.max(x,y):最大值 Math.min(x,y):最小值 Math.r ...
- css—文字渐变色
.text-gradient { display: inline-block; color: green; font-size: 10em; font-family: ´微软雅黑´; backgrou ...
- 文件IO详解(四)---标准输入、标准输出和标准错误
每个进程都会默认打开3个文件描述符,即0.1.2.其中0代表标准输入流.1代表标准输出流.2代表标准错误流.通常标准输入流对应着键盘的设备文件.标准输出流和错误流对应着显示器的设备文件.在编程中通常使 ...
- Mysql 5.7 for windows 免安装版(解压版)安装和配置
网上写的不近详细,这里重新整理下. 准备: 1.windows操作系统 2.mysql 的解压版压缩文件 第一步: 解压mysql的压缩包到你的安装目录,因为是虚拟机,这里我就安装在C盘下:C:\my ...
- windows系统下jenkins环境搭建与基本使用
一. windows 系统下搭建jenkins环境 1.1 jenkins环境搭建和构建job流程图 1.2 安装jdk JDK下载地址: http://www.oracle.com/technet ...
- Unicode编码,解释UCS、UTF、BMP、BOM等名词
(转载 谈谈Unicode编码,简要解释UCS.UTF.BMP.BOM等名词 这是一篇程序员写给程序员的趣味读物.所谓趣味是指可以比较轻松地了解一些原来不清楚的概念,增进知识,类似于打RPG游戏的升级 ...
- MYSQL存储过程初步认知
存储过程(Stored Procedure): 一组可编程的函数,是为了完成特定功能的SQL语句集,经编译创建并保存在数据库中,用户可通过指定存储过程的名字并给定参数(需要时)来调用执行. 优点:将重 ...
- solrj 操作 solr 集群版
一.添加 @Test public void testAddDocument() throws Exception{ //创建一个集群的连接,应该使用 CloudSolrServer,//zkHost ...
- POJ 4786 Fibonacci Tree
Fibonacci Tree Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ...
- 洛谷 1144 最短路计数 bfs
洛谷1144 最短路计数 传送门 其实这道题目的正解应该是spfa里面加一些处理,,然而,,然而,,既然它是无权图,,那么就直接bfs了,用一个cnt记录一下每一个点的方案数,分几种情况讨论一下转移, ...