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 ...
随机推荐
- 优动漫PAINT(clip studio paint)提示无法连接服务器
很多同学在使用优动漫PAINT进行艺术创作的时候,软件会出现无法连接服务器的提示,遇到此情况如何解决呢?目前,软件在Windows系统和Mac系统上的解决方法有别,请悉知: 1.曾使用过,或正在使用F ...
- vue.js怎样将时间戳转化为日期格式
<!-- value 格式为13位unix时间戳 --><!-- 10位unix时间戳可通过value*1000转换为13位格式 --> export function for ...
- 四种ASP网页跳转代码
时间:2012-06-12 21:12来源:未知 输入:铜都风尘 点击: 32987 次 如果你要在服务器端跳转,可以这样: Response.Redirect(http://blog.163.com ...
- Project Euler 15 Lattice paths
题意:在20×20方阵中从起点出发只允许向右或向下移动到达终点的路径有多少条. 思路:每次只能向右或者向下,总共 40 步,也就是 40 步中每一步都有两种选择,也就是 C (40 , 20) . 为 ...
- 洛谷 P1567 统计天数
题目背景 统计天数 题目描述 炎热的夏日,KC非常的不爽.他宁可忍受北极的寒冷,也不愿忍受厦门的夏天.最近,他开始研究天气的变化.他希望用研究的结果预测未来的天气. 经历千辛万苦,他收集了连续N(1& ...
- Linux菜鸟成长日记 ( Linux 下的 ftp 文件传输协议 )
https://blog.csdn.net/buster_zr/article/details/80244542 FTP FTP 是 File Transfer Protocol (文件传输协议)的英 ...
- SSH框架整合截图总结(一)
分页相关属性 --------------------------------------------------------------- 分页思路表单提交(只需传递当前页的值) ->acti ...
- BLOB的读写操作
//BLOB写入操作package zxt.xsfw.action.ceshi; import javax.servlet.http.HttpServletRequest; import javax. ...
- 判断webservice是否可用
在.net中验证WebService的Url有效并且验证服务可用: 需要用到win32下的组件,比如Microsoft XML, v5.0 测试程序具体如下:建一个项目,在你的引用中添加COM---找 ...
- G - Arctic Network
G - Arctic Network #include<cmath> #include<cstdio> #include<cstring> #include&l ...