步步为营-86-WSFUpload组件
文件上传组件,所需js文件和图片在百度网盘对应的文件夹下
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SWFUpload_Demo.aspx.cs" Inherits="BookShop.Web.Test.SWFUpload_Demo" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script src="../../js/jquery-1.7.1.js"></script>
<script src="../handlers.js"></script>
<script src="../swfupload.js"></script>
<script type="text/javascript">
var swfu;
window.onload = function () {
swfu = new SWFUpload({
//指定要上传的路径
upload_url: "/ashx/FileUpload.ashx",
post_params: {
"ASPSESSID": "<%=Session.SessionID %>"
}, // File Upload Settings
file_size_limit: "2 MB",
file_types: "*.jpg;*.gif",
file_types_description: "JPG Images",
file_upload_limit: , // Zero means unlimited // 事件处理了的三个主要方法定义在 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: showImage,
upload_complete_handler: uploadComplete, // 按钮设置
button_image_url: "/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: "/SWFUpload/swfupload.swf", // Relative to this file
flash9_url: "/SWFUpload/swfupload_FP9.swf", // Relative to this file custom_settings: {
upload_target: "divFileProgressContainer"
}, // Debug Settings
debug: false
});
}
//上传成功以后调用该方法
function showImage(file, serverData) {
$("#showPhoto").attr("src", serverData);
} </script>
</head>
<body>
<form id="form1" runat="server"> <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>
<img id="showPhoto"></img>
</div>
</div>
</form>
</body>
</html>
前台代码
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web; namespace BookShopManager.Web.Ashx
{
/// <summary>
/// FileUpload 的摘要说明
/// </summary>
public class FileUpload : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
HttpPostedFile file = context.Request.Files["Filedata"];
if (file != null)
{
string fileName = Path.GetFileName(file.FileName);
string fileExt = Path.GetExtension(fileName);
if (fileExt == ".jpg")
{
string dir = "/FileUpload/" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + "/";
if (!Directory.Exists(context.Request.MapPath(dir)))
{
Directory.CreateDirectory(context.Request.MapPath(dir));
}
string newFileName = Guid.NewGuid().ToString();
string fullDir = dir + newFileName + fileExt;
file.SaveAs(context.Request.MapPath(fullDir));
context.Response.Write(fullDir);
}
}
} public bool IsReusable
{
get
{
return false;
}
}
}
}
服务器端代码
步步为营-86-WSFUpload组件的更多相关文章
- 谈谈我对前端组件化中“组件”的理解,顺带写个Vue与React的demo
前言 前端已经过了单兵作战的时代了,现在一个稍微复杂一点的项目都需要几个人协同开发,一个战略级别的APP的话分工会更细,比如携程: 携程app = 机票频道 + 酒店频道 + 旅游频道 + ..... ...
- React Native知识4-Image组件
一个用于显示多种不同类型图片的React组件,包括网络图片.静态资源.临时的本地图片.以及本地磁盘上的图片(如相册)等 一:属性 1:onLayout function 当元素挂载或者布局改变的时候调 ...
- [分享] 《步步为营封 Win7》--skyfree
[分享] <步步为营封 Win7>--skyfree Skyfree 发表于 2009-9-13 05:51:32 https://www.itsk.com/thread-20957-1- ...
- 【腾讯Bugly干货分享】微信终端跨平台组件 mars 系列(一) - 高性能日志模块xlog
本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/57ff5932cde42f1f03de29b1 本文来源: 微信客户端开发团队 ...
- Tomcat源码分析之—组件启动实现分析
Tomcat由多个组件组成,那么Tomcat是怎么对他们的生命周期进行管理的么,这里将从Tomcat源码去分析其生命周期的实现: Bootstrape类为Tomcat的入口,所有的组件够通过实现Lif ...
- javaWeb---文件上传(commons-FileUpload组件)
FileUpload是Apache组织(www.apache.org)提供的免费的上传组件,但是FileUpload组件本身还依赖于commons组件,所以从Apache下载此组件的时候还需要连同co ...
- Android组件系列----Android Service组件深入解析
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...
- 转-Fragment+ViewPager组件(高仿微信界面)
http://www.cnblogs.com/lichenwei/p/3982302.html 什么是ViewPager? 关于ViewPager的介绍和使用,在之前我写过一篇相关的文章<安卓开 ...
- 转-ViewPager组件(仿微信引导界面)
http://www.cnblogs.com/lichenwei/p/3970053.html 这2天事情比较多,都没时间更新博客,趁周末,继续继续~ 今天来讲个比较新潮的组件——ViewPager ...
随机推荐
- 用NAME_N带入NAME 让显示格式变为 姓名(类型),类型在数据库中是1和0,显示效果为姓名(1),SQL写法
select xxxx T.PROJECT_NAME||'('||DECODE(T.PROJECT_TYPE,'1','收入','2','支出','3','挂账')||')' PROJECT_NAME ...
- python3+selenium入门14-上传下载文件
上传文件一种方式是通过定位input标签,然后使用send_keys()方法传入需要上传文件的路径.另一种是使用第三方插件去上传文件.下面看下imput标签的方式.工具可以自己查下. <!DOC ...
- requests库入门09-OAUTH认证
实际登陆中,认证用到的token会变的,不过可以在GIthub设置一个私人token. 如图,登录GIthub,然后用户下面选择Settings/Developer settings/Personal ...
- Xml 文件读取
.NET 读取Xml文件,用到XmlDocument类. 1.要获取文档的根: DocumentElement. 2.Attributes :获取 XmlAttributeCollection 包含此 ...
- MYSQL在centos上主从配置
主从配置理论传送门:http://blog.csdn.net/hguisu/article/details/7325124 具体配置方案: 一:MYSQL主从配置 1.1 部署环境 主(maste ...
- webp 图形文件操作工具包 win32 (编译 libwebp-20171228-664c21dd 版本)
源码下载地址 https://chromium.googlesource.com/webm/libwebp/ 版本 libwebp-20171228-664 ...
- 外网zabbix-server使用主动模式监控公司内网windows服务器
外网zabbix-server使用主动模式监控公司内网windows服务器 1.Zabbix Agent active批量调整客户端为主动模式监控将Template OS Windows模板调整为主动 ...
- 最新sublime text 3 注册码license分享(亲测有效)
—– BEGIN LICENSE —– TwitterInc 200 User License EA7E-890007 1D77F72E 390CDD93 4DCBA022 FAF60790 61AA ...
- ubuntu中文版man
man默认是英文的,但ubuntu的源里也有中文版的.以下是配置方法: 1) 终端输入sudo apt-get install manpages-zh 2) 安装后修改配置文件sudo gedit ...
- 51nod--1265 四点共面 (计算几何基础, 点积, 叉积)
题目: 1265 四点共面 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 给出三维空间上的四个点(点与点的位置均不相同),判断这4个点是否在同一个平面内(4 ...