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;
        }
    }

}

 

posted @ 2013-06-16 13:12  cclient  阅读(317)  评论(0编辑  收藏  举报