uploadify上传控件
来源:互联网 发布:淘宝买的鞋子开胶了 编辑:程序博客网 时间:2024/05/03 17:21
下载控件:uploadify 分为2种,选择Flash Version版本
地址:http://www.uploadify.com/
页面代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Upload.aspx.cs" Inherits="Hot.Upload" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <link href="Scripts/upload/uploadify.css" rel="stylesheet" /> <script src="Scripts/jquery-1.7.1.min.js"></script> <script src="Scripts/upload/jquery.uploadify.min.js"></script> <title>上传控件</title> <script type="text/javascript"> $(document).ready(function () { $("#uploadify").uploadify({ 'swf': 'Scripts/upload/uploadify.swf', 'uploader': '/UploadHandler.ashx', 'cancelImg': 'Scripts/upload/uploadify-cancel.png', 'queueID': 'fileQueue', 'uploadLimit': 1000, //一次浏览器课上成总数量 //'fileSizeLimit': '100MB', //单个文件大小设置 'auto': false, 'multi': true, 'onFallback':function(){ alert("您未安装FLASH控件,无法上传图片!请安装FLASH控件后再试。"); }, //返回一个错误,选择文件的时候触发 'onSelectError': function (file, errorCode, errorMsg) { switch (errorCode) { case -100: alert("上传的文件数量已经超出系统限制的" + $('#file_upload').uploadify('settings', 'queueSizeLimit') + "个文件!"); break; case -110: alert("文件 [" + file.name + "] 大小超出系统限制的" + $('#file_upload').uploadify('settings', 'fileSizeLimit') + "大小!"); break; case -120: alert("文件 [" + file.name + "] 大小异常!"); break; case -130: alert("文件 [" + file.name + "] 类型不正确!"); break; } alert(errorCode); }, 'onUploadStart': function (file) { }, 'onUploadSuccess': function (file, data, response) { $('#' + file.id).find('.data').html(' 上传完毕'); }, 'onUploadComplete': function () { } }); }); </script></head><body> <div id="fileQueue"></div> <input type="file" name="uploadify" id="uploadify" /> <p> <a href="javascript:$('#uploadify').uploadify('upload','*')">上传</a>| <a href="javascript:$('#uploadify').uploadify('cancel', '*')">取消上传</a> </p> </body></html>
上传到后台:
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Web;namespace Hot{ /// <summary> /// UploadHandler 的摘要说明 /// </summary> public class UploadHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //接收上传后的文件 HttpPostedFile file = context.Request.Files["Filedata"]; //其他参数 //string somekey = context.Request["someKey"]; //string other = context.Request["someOtherKey"]; //获取文件的保存路径 创建uploads文件夹 string uploadPath =HttpContext.Current.Server.MapPath("uploads" + "\\"); //判断上传的文件是否为空 if (file != null) { if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } //1.利用InputStream 属性直接从HttpPostedFile对象读取文本内容 System.IO.Stream MyStream; int FileLen; FileLen = file.ContentLength; // 读取文件的 byte[] byte[] bytes = new byte[FileLen]; MyStream = file.InputStream; MyStream.Read(bytes, 0, FileLen); //2.保存到文件 file.SaveAs(uploadPath + file.FileName); context.Response.Write("1"); } else { context.Response.Write("0"); } } public bool IsReusable { get { return false; } } }}
1.记得创建uploads文件夹,放上传的文件。
2.$('#' + file.id).find('.data').html(' 上传完毕'); 是设置显示为中文完成,不然是英文,也可以更改jquery.uploadify.js文件里的英文字。
0 0
- uploadify上传控件
- 文件上传控件Uploadify
- uploadify上传控件使用
- jquery文件上传控件 Uploadify
- jquery文件上传控件 Uploadify
- jquery文件上传控件 Uploadify
- jquery文件上传控件 Uploadify
- jquery文件上传控件 Uploadify
- Uploadify 控件上传图片 + 预览
- Jquery文件上传控件Uploadify
- jquery文件上传控件 Uploadify
- jQuery文件上传控件 Uploadify
- Jquery上传文件控件Uploadify
- 上传控件Uploadify,jQuery遮罩层
- jquery文件上传控件 Uploadify
- jquery文件上传控件 Uploadify
- jquery文件上传控件 Uploadify
- 使用uploadify控件上传文件
- hadoop0.20.2中的KeyValueInputFormat
- C# .net 如何抓取网页内容
- new 和 alloc/init 的差别
- EVT、DVT、PVT、MP等简介
- 黑马程序员——【Java】IO——File:遍历目录下java文件
- uploadify上传控件
- 自动检测iOS网络并可跳转至设置界面设置网络
- Jsp 显示图片问题(相对路径)
- C++位运算
- DWR入门教程
- 黑马程序员——【Java】IO——Properties基本
- 链表倒数第k个结点
- 黑马程序员——【Java】IO——打印流
- C/C++软件工程师就业求职手册学习笔记---第七章