文件上传组件,所需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组件的更多相关文章

  1. 谈谈我对前端组件化中“组件”的理解,顺带写个Vue与React的demo

    前言 前端已经过了单兵作战的时代了,现在一个稍微复杂一点的项目都需要几个人协同开发,一个战略级别的APP的话分工会更细,比如携程: 携程app = 机票频道 + 酒店频道 + 旅游频道 + ..... ...

  2. React Native知识4-Image组件

    一个用于显示多种不同类型图片的React组件,包括网络图片.静态资源.临时的本地图片.以及本地磁盘上的图片(如相册)等 一:属性 1:onLayout function 当元素挂载或者布局改变的时候调 ...

  3. [分享] 《步步为营封 Win7》--skyfree

    [分享] <步步为营封 Win7>--skyfree Skyfree 发表于 2009-9-13 05:51:32 https://www.itsk.com/thread-20957-1- ...

  4. 【腾讯Bugly干货分享】微信终端跨平台组件 mars 系列(一) - 高性能日志模块xlog

    本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/57ff5932cde42f1f03de29b1 本文来源: 微信客户端开发团队 ...

  5. Tomcat源码分析之—组件启动实现分析

    Tomcat由多个组件组成,那么Tomcat是怎么对他们的生命周期进行管理的么,这里将从Tomcat源码去分析其生命周期的实现: Bootstrape类为Tomcat的入口,所有的组件够通过实现Lif ...

  6. javaWeb---文件上传(commons-FileUpload组件)

    FileUpload是Apache组织(www.apache.org)提供的免费的上传组件,但是FileUpload组件本身还依赖于commons组件,所以从Apache下载此组件的时候还需要连同co ...

  7. Android组件系列----Android Service组件深入解析

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...

  8. 转-Fragment+ViewPager组件(高仿微信界面)

    http://www.cnblogs.com/lichenwei/p/3982302.html 什么是ViewPager? 关于ViewPager的介绍和使用,在之前我写过一篇相关的文章<安卓开 ...

  9. 转-ViewPager组件(仿微信引导界面)

    http://www.cnblogs.com/lichenwei/p/3970053.html 这2天事情比较多,都没时间更新博客,趁周末,继续继续~ 今天来讲个比较新潮的组件——ViewPager ...

随机推荐

  1. 1173 - The Vindictive Coach

    题目大意:n个不同身高的队员和教练的按照身高排成波浪形……每个人按照身高由低到高编号,其中第m个是教练,他必须在第一个,如果条件允许,排第二的要比m低,如果条件不允许,即其余人都比教练高,则要让差距尽 ...

  2. python第三天,字符串续

    字符串类型 在python中字符串类型可以用 成对单引号,如:'你好,中国.': 也可以用成对双引号,如:"厉害了,我滴国".代码如下: 通过.title(),可以将一段话的首字母 ...

  3. 生产者消费者模型java

    马士兵老师的生产者消费者模型,我感觉理解了生产者消费者模型,基本懂了一半多线程. public class ProducerConsumer { public static void main(Str ...

  4. Java中通过脚本引擎调用js函数

    import java.io.*; import javax.script.Invocable; import javax.script.ScriptEngine; import javax.scri ...

  5. Jquery的一些常见用法

    谨以此文怀念我们大学的时光,Jquery3.4.0下载 https://code.jquery.com/jquery-3.4.0.min.js ⒈常用方法 $("#div1").h ...

  6. [转]python3之paramiko模块(基于ssh连接进行远程登录服务器执行命令和上传下载文件的功能)

    转自:https://www.cnblogs.com/zhangxinqi/p/8372774.html 阅读目录 1.paramiko模块介绍 2.paramiko的使用方法 回到顶部 1.para ...

  7. WINDOWS系统中常用网络命令及命令实例详解

    一.查询DNS.IP,mac地址及DHCP服务的情况 二.查看ARP表:MAC地址与IP地址的映射表 三.查看共享资源 四.查看局域网内的主机名 五.查看用户列表  六.路由跟踪命令 七.查看共享资源 ...

  8. SharePoint 2013: Workflow Manager Backend 服务意外地终止

    一.环境:SharePoint 2013 + Workflow Manager 1.0 二.错误描述: Workflow Manager Backend 服务意外地终止,这种情况已经出现了 42106 ...

  9. java 解压缩 中文名称问题

    public List<String> unZip(String pathString, String zipPathString) { long startTime = System.c ...

  10. live555运行时报错:StreamParser internal error ( 86451 + 64000 > 150000)

    搭建好live555服务器后,使用 vlc播放网络视频.此时服务器端报如下错误: StreamParser internal error ( 86451 + 64000   > 150000). ...