用jquery uploadify上传插件上传文件

 public void ProcessRequest(HttpContext context)
    {
        string esOIDs = System.Web.HttpContext.Current.Request["esOIDs"];
        string userID=System.Web.HttpContext.Current.Session["USER_ID"].ToString();

        context.Response.ContentType = "text/plain";
        context.Response.Charset = "utf-8";

        HttpPostedFile file = context.Request.Files["Filedata"];
        string Path = HttpContext.Current.Server.MapPath(@context.Request["folder"]) + "\\AccessoryFiles";

        if (!Directory.Exists(Path))//判断文件是否存在
        {
            Directory.CreateDirectory(Path);
        }

        if (file != null)
        {
            if (file.ContentLength <= 1024 * 1024 * 1024)//限定文件小于100M
            {
                bool fileOK = false;
                string fileExtension = System.IO.Path.GetExtension(file.FileName).ToLower(); //得到选择文件 扩展名

                string[] allowedExtensions = { ".doc", ".docx", ".ppt", ".pptx", ".xls", ".xlsx", ".pdf",".wmv",".avi", ".gif", ".png", ".bmp", ".jpg", ".mp4", ".rar", ".zip" }; //可上传文件类型列表
                for (int i = 0; i < allowedExtensions.LongLength; i++)//判断上传文件是否为上述合法类型
                {
                    if (fileExtension == allowedExtensions[i])
                    {
                        fileOK = true;
                        break;
                    }
                }

                if (fileOK == true)//如果文件格式正确
                {
                    string uploadPath = Path + "\\" + esOIDs;
                    if (!Directory.Exists(uploadPath))//判断文件是否存在
                    {
                        Directory.CreateDirectory(uploadPath);
                    }

                    string fileNewName = DateTime.Now.ToString("yyyyMMddHHmmss") + System.IO.Path.GetExtension(file.FileName).ToLower();
                    file.SaveAs(uploadPath + "\\" + fileNewName);

                    if (!Directory.Exists(uploadPath + "\\" + fileNewName))
                    {
                        AccessoryObj accessoryObj = new AccessoryObj();
                        accessoryObj.REFOID = esOIDs;
                        accessoryObj.ReftypeVal = AccessoryType.项目;
                        accessoryObj.FILENAME = file.FileName;
                        accessoryObj.FILETYPE = fileExtension;
                        accessoryObj.FILEPATH = "FileUpLoad/AccessoryFiles/" + esOIDs + "/" + fileNewName;
                        accessoryObj.UPLOADUSER = userID;
                        accessoryObj.UPLOADDATE = DateTime.Now;

                        List<AccessoryObj> accList = new List<AccessoryObj>();
                        accList.Add(accessoryObj);
                        new AccessoryRepository().AddAccessoryObj(accList);
                    }

                    //下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失
                    context.Response.Write("1");
                }
            }
        }
        else
        {
            context.Response.Write("0");
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

uploadhandler。ashx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUpLoad.aspx.cs" Inherits="FileUpLoad" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
 <head id="Head1" runat="server">
  <title></title>
//去网上download一个jquery uploadify插件 ,这些文件都有
   <script src="../../Scripts/jquery/jquery.uploadify/jquery-1.3.2.min.js" type="text/javascript"></script>
 <script src="../../Scripts/jquery/jquery.uploadify/jquery.uploadify.v2.1.0.min.js"         type="text/javascript"></script>     <script src="../../Scripts/jquery/jquery.uploadify/swfobject.js" type="text/javascript"></script>     <link rel="stylesheet" type="text/css" href="../../Scripts/jquery/jquery.uploadify/uploadify.css" />   

<script type="text/javascript">
   $(document).ready(function () {
      $("#uploadify").uploadify({
 ‘uploader‘: ‘../../Scripts/jquery/jquery.uploadify/uploadify.swf‘,
    ‘script‘: ‘UploadHandler.ashx?esOIDs=<%=esOIDs %>‘,
    ‘cancelImg‘: ‘../../Scripts/jquery/jquery.uploadify/cancel.png‘,
           ‘folder‘: ‘../../FileUpLoad/‘,
        ‘queueID‘: ‘fileQueue‘,
     ‘auto‘: false,
     ‘multi‘: true,
  ‘buttonText‘: ‘‘,
   ‘fileDesc‘ :‘可选择类型:.doc/.rar/.docx/.ppt/.pptx/.xls/.xlsx/.pdf/.gif/.png/.bmp/.jpg/.mp4/.rar/.wmv/.avi/.zip‘,
      ‘fileExt‘: ‘*.doc;*.rar;*.docx;*.ppt;*.pptx;*.xls; *.xlsx;*.pdf;*.gif;*.png;*.bmp;*.jpg;*.mp4;*.rar;*.wmv;*.avi;*.zip‘,                 ‘sizeLimit‘: 1024 * 1024 * 1024,
    ‘buttonImg‘: ‘../../Scripts/jquery/jquery.uploadify/browse.png‘,
            ‘height‘:‘20‘,
     ‘width‘: ‘50‘
 });
  });
    </script>
</head>
<body>
  <form id="form1" runat="server">
 <div id="fileQueue" style="height: 400px">     </div>
<table>
    <tr>
   <td style="text-align: inherit">
    <input type="file" name="uploadify" id="uploadify" onclick="return uploadify_onclick()" />
            <input name="" onclick="javascript:$(‘#uploadify‘).uploadifyUpload()" type="button" style="height:20px"  value="上传" />
    <input name="" onclick="javascript:$(‘#uploadify‘).uploadifyClearQueue()" type="button" style="height:20px"  value="取消上传" />
     </td>
 </tr>
</table>
  </form>
 </body> </html>
时间: 2024-07-29 18:27:10

用jquery uploadify上传插件上传文件的相关文章

使用jQuery Uploadify在ASP.NET 上传附件 (转)

Uploadify是JQuery的一个上传插件,实现的效果非常不错,带进度显示.Uploadify官方网址:http://www.uploadify.com/,在MVC中使用的方法可以参考 jQuery Uploadify在ASP.NET MVC3中的使用 和 Asp.net Mvc中使用uploadify实现图片缩放保存. 本文是一个简单的介绍Demo,主要是动态传递参数方法:通过formdata 向处理程序传递额外的表单数据: <!DOCTYPE html PUBLIC "-//W3C

在php中使用jquery uploadify进行多图片上传

jquery uploadify是一款Ajax风格的批量图片上传插件,在PHP中使用jquery uploadify很方便,请按照本文介绍的方法和步骤,为你的PHP程序增加jquery uploadify插件的批量上传图片功能. 本文是以dilicms为基础,为其增加图片上传功能. 1.增加数据表dili_fieldtypes新字段:k=>image,V=>图片上传区域(VACHAR): 2.修改application/libraries/dili/Field_behavior.php,在sw

[推荐]两款Flash上传插件(1)–CFUpdate文件批量上传组件

搞开发的同学都知道,网上可搜到的可用的Flash图片上传的组件少之又少,可定制界面,不需要安装组件,且可免费用于任何商业系统的,更是凤毛麟角,如果你和我一样,迫切需要一款这样的一款组件的话,不妨试试CFUpdate吧. 以下是我修改的一个Demo效果,你也可以猛击此处查看在线Demo. CFUpdate可选择多个图片上传,显示上传速度.进度条.文件名称等,可拖动排序文件顺序,CFUpdate使用的是HTTP协议,所以客户 端,服务端都不需要安装任何组件.因为是模仿FORM表单提交,所以支持ASP

jQuery上传插件Uploadify使用帮助

Uploadify是JQuery的一个上传插件,实现的效果非常不错,带进度显示.它的功能特色总结如下: 支持单文件或多文件上传,可控制并发上传的文件数 在服务器端支持各种语言与之配合使用,诸如PHP,.NET,Java…… 通过参数可配置上传文件类型及大小限制 通过参数可配置是否选择文件后自动上传 易于扩展,可控制每一步骤的回调函数(onSelect, onCancel……) 通过接口参数和CSS控制外观 使用帮助: 官网地址:http://www.uploadify.com/ 官方参数配置文档

可拖拽和带预览图的jQuery文件上传插件ssi-uploader

插件描述:ssi-uploader是一款带预览图并且可以拖拽文件的jQuery ajax文件上传插件.该文件上传插件支持AJAX,支持多文件上传,可控制上的文件格式和文件大小,提供各种回调函数,使用非常方便. 简要教程 ssi-uploader是一款带预览图并且可以拖拽文件的jQuery ajax文件上传插件.该文件上传插件支持AJAX,支持多文件上传,可控制上的文件格式和文件大小,提供各种回调函数,使用非常方便. 安装 可以通过bower或npm来安装ssi-uploader文件上传插件. b

jQuery打造智能提示插件二(可编辑下拉框)

在上一篇 jQuery打造智能提示插件 上改进,增加下拉按钮,修复点击下拉区域外不隐藏BUG 效果 下拉按钮素材: js封装,注意红色部分为BUG修复,然后传入boxwidth不带px: /* /// <reference path="jquery-autocomplete2.0.js" /> zhangs 20140516 */ (function($) { $.fn.combox = function(options) { var KEY = { UP: 38, DOW

jQuery上传插件Uploadify出现Http Error 302错误解决

前段时间介绍过jquery uploadify上传插件的使用方法,我在使用中遇到过Http Error 302错误问题,应该会有很多人在使用中遇到过,在此记录下来: 首 先http 302是请求被重定向的意思,这就很容易理解了,如果你的uploadify处理上传脚本有session验证,就会出现此错误,因为flash在执行 post请求的时候没有包含cookie信息,而服务器的session会根据客户端的cookie来得到SESSIONID.没有提交cookie自然 就不能获取到session,

支持多文件上传的jQuery文件上传插件Uploadify

支持多文件上传的jQuery文件上传插件Uploadify,目前此插件有两种版本即Flash版本和HTML5版本,对于HTML5版本会比较好的支持手机浏览器,避免苹果手机Safari浏览器不支持Flash,主要特性:支持多文件上传.HTML5版本可拖拽上传.实时上传进度条显示.强大的参数定制功能,如文件大小.文件类型.按钮图片定义.上传文件脚本等. Flash版本使用方法: 1.加载JS和CSS ? 1 2 3 <script src="jquery/1.7.1/jquery.min.js

强大的支持多文件上传的jQuery文件上传插件Uploadify

支持多文件上传的jQuery文件上传插件Uploadify,目前此插件有两种版本即Flash版本和HTML5版本,对于HTML5版本会比较好的支持手机浏览器,避免苹果手机Safari浏览器不支持Flash,主要特性:支持多文件上传.HTML5版本可拖拽上传.实时上传进度条显示.强大的参数定制功能,如文件大小.文件类型.按钮图片定义.上传文件脚本等. Flash版本使用方法: 1.加载JS和CSS ? 1 2 3 <script src="jquery/1.7.1/jquery.min.js