zoukankan      html  css  js  c++  java
  • jquery.uploadify的使用

    HTML

       <div id="localvideo1">
                                  <div id="fileQueue"  runat="server"></div>
                                    <input type="file" name="uploadify" id="uploadify" />
    
          <a href="javascript:$('#uploadify').uploadifyUpload()">上传</a>| 
          <a href="javascript:$('#uploadify').uploadifyClearQueue()">取消上传</a>
    
                            <input  type="hidden" id="videoname" runat="server"/>
                               
     </div>

    JS

    $(document).ready(function() {
             $("#uploadify").uploadify({
                 'uploader': 'js/jquery.uploadify-v2.1.0/uploadify.swf',
                 'script': 'UploadHandler.ashx',
                 'cancelImg': 'js/jquery.uploadify-v2.1.0/cancel.png',
                 'queueID': 'fileQueue',
                 'auto': false,
                 'multi': false,
                 'fileExt': '*.mp4;*.flv;*.swf;*.avi',
                 'fileDesc': '请选择mp4 flv swf avi文件',
                 'buttonText ': '浏览',
                 'onComplete': function(event, ID, fileObj, response, data) {
                     $("#videoname").val(response);
                     alert("上传成功");
    
                 }
             });
         });  

    C#后台

    <%@ WebHandler Language="C#" Class="UploadHandler" %>
    
    using System;
    using System.Web;
    
    public class UploadHandler : IHttpHandler {
    
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Charset = "utf-8";
    
            HttpPostedFile file = context.Request.Files["Filedata"];
           string uploadPath =
                HttpContext.Current.Server.MapPath("Video") + "\\";
            string datetime = DateTime.Now.ToLocalTime().ToString().Replace(':','-');
            if (file != null)
            {
               
                string FileDir = file.FileName;
                       string FileName = FileDir.Substring(0,FileDir.LastIndexOf("."));                  //获取上传文件名称
                       string FileNameType = FileDir.Substring(FileDir.LastIndexOf(".") + 1).ToString();    //获取上传文件类型
                       string path = uploadPath + FileName + datetime +"."+ FileNameType;
    
                       file.SaveAs(path);
                //下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失
                       context.Response.Write(FileName+datetime + "." + FileNameType);
            }
            else
            {
                context.Response.Write("0");
            }
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }
    
    }
  • 相关阅读:
    mysql 语法
    mycat 配置简介
    redis sentinel 配置
    Spark SQL 读到的记录数与 hive 读到的不一致
    HDP3.1 中 YRAN 和 MR2 的内存大小配置的计算方式
    在 windows 下搭建 IDEA + Spark 连接 Hive 的环境
    HDP3.1 中配置 YARN 的 timeline server 使用外部的 HBase
    大规模使用 Apache Kafka 的20个最佳实践
    卸载mac版本的GlobalProtect
    js解决约瑟夫问题
  • 原文地址:https://www.cnblogs.com/zihunqingxin/p/3138725.html
Copyright © 2011-2022 走看看