Jquery.Uploadify 上传文件插件的使用

事先要将uploadify插件引入到解决方案中,可去uploadify官网下载;此例子是在MVC中进行的实现;脚本代码段:
<script src="~/Scripts/jquery-1.11.1.min.js"></script><script src="~/Scripts/Common/uploadify/[email protected](new Random().Next())[email protected](new Random().Next())"></script>
<script>
    $(‘#uploadify‘).uploadify({
        uploader: ‘/SocialSecurity/Upload‘,           // 服务器端处理地址
        swf: ‘../Scripts/Common/uploadify/uploadify.swf‘,    // 上传使用的 Flash
        width: 60,                          // 按钮的宽度
        height: 23,                         // 按钮的高度
        buttonText: "上传",                 // 按钮上的文字
        buttonCursor: ‘hand‘,                // 按钮的鼠标图标
        fileObjName: ‘Filedata‘,            // 上传参数名称
        fileSizeLimit: ‘51200K‘,//1M:1*1024*1024
        // 两个配套使用
        fileTypeExts: "*.gif;*.jpg;*.jpeg;*.png;*.GIF;*.JPG;*.PNG;",             // 扩展名
        fileTypeDesc: "请选择 gif|jpg|jpeg|png 文件",     // 文件说明
        auto: true,                // 选择之后,自动开始上传
        //multi: true,               // 是否支持同时上传多个文件
        //queueSizeLimit: 5,          // 允许多文件上传的时候,同时上传文件的个数
        removeCompleted: false,     //文件上传完成后,是否自动移除队列中的文件
        uploadLimit: 1,  //最大上传文件数量,如果达到或超出此限制将会触发onUploadError事件。
        onInit: function () {
            $("#uploadify-queue").hide();//隐藏上传进度和上传文件的大小
        },
        onSelect: function (file) {   //选择文件后向队列中添加每个上传任务时都会触发。
            auto_boxHeight(‘ifm4‘, 30);
        },
        onUploadSuccess: function (file, data, response) {
            $("#hf_uploadURL").val(data);
            alert("上传成功");
        }
    });

</script>

html标签:

<div class="fl lh45form bdLeft" style="width:370px;padding-left:50px;">
                    <h3 class="ml5">资料上传</h3>
                    <table class="tb_form">
                        <tr>
                            <td class="tx_left" width="27%">生效时间</td>
                            <td class="tx_left"><input type="text" class="timeInput" name="effectiveTime" id="txtEffectiveTime" onclick="WdatePicker({ minDate: ‘%y-%M-01‘, dateFmt: ‘yyyy-M‘ });" value=""></td>
                        </tr>
                        <tr>
                            <td class="tx_left">上传证明资料</td>
                            <td class="tx_left btnC">
                                <span id="uploadify"></span>
                                <input type="hidden" id="hf_uploadURL" name="uploadURL" />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" class="tx_left">备注: XXXX</td>
                        </tr>
                    </table>
                </div>

  后台Controller.cs代码段:

public ActionResult Upload(HttpPostedFileBase Filedata)
        {
            // 如果没有上传文件
            if (Filedata == null ||
                string.IsNullOrEmpty(Filedata.FileName) ||
                Filedata.ContentLength == 0)
            {
                return this.HttpNotFound();
            }
            //文件是否存在
            if (!Directory.Exists(Server.MapPath("~/Upload")))
            {
                Directory.CreateDirectory(Server.MapPath("~/Upload"));
            }
            //文件下的文件是否存在
            string fileName = "~/Upload/SocialSecurityFile";
            if (!Directory.Exists(Server.MapPath(fileName)))
            {
                Directory.CreateDirectory(Server.MapPath(fileName));
            }
            // 保存到 ~/photos 文件夹中,名称不变
            string filename = System.IO.Path.GetFileName(Filedata.FileName);

            string allFileName = Guid.NewGuid().ToString("N");//得到一个32位的数字,国际唯一字符
            string virtualPath = string.Format("~/Upload/SocialSecurityFile/{0}_{1}", allFileName, filename);
            // 文件系统不能使用虚拟路径
            string path = this.Server.MapPath(virtualPath);

            Filedata.SaveAs(path);
            var url = FuncFileUpload.Instance.Upload(path);//此代码是将代码服务器中的文件资源上传至文件资源服务器中,也可直接返回path值(代码服务器上的文件路径值)
            System.IO.File.Delete(path);

            return Content(url);
        }

  到此,运行即可看到上传的效果;

时间: 2024-07-29 18:27:08

Jquery.Uploadify 上传文件插件的使用的相关文章

[Plugin] JQuery.uploadify上传文件插件的使用详解For ASP.NET

URL:http://www.cnblogs.com/xiaopin/archive/2010/01/21/1653523.html 今天下午整理文件上传的例子,感觉收集到的例子都很不人性话,后来找到一个还可以的,本来想改成类似于腾讯QQ相册那种方式,仔细看了一下是Flash的, 而且那个极速上传插件也不知道用什么做的?问了一下,说是什么cgi. 搞得一头雾水! 后来朋友推荐了一个这个叫uploadify的上传插件,似乎挺好,就到官方下了个示例运行,感觉挺好,自己再稍加美化一下就OK 了..!

jquery uploadify上传文件插件导致浏览器崩溃问题解决方法

自谷歌浏览器更新到(版本39.0.2171.99 )后,访问上传文件界面浏览器就崩溃了,而其他的浏览器不会出现问题. 出现这种问题的原因就是谷歌浏览器缓存问题,但将访问该jsp页面路径添加上时间戳后无法解决问题,将界面引入uploadify.js中也添加了个随机变量还是不行.最后将引入js换成下面形式就解决了: 代码如下: [javascript] view plaincopyprint? document.write("<script type='text/javascript' &qu

MVC3+jquery Uploadify 上传文件

最近做项目用到了上传图片的功能,以前也写过这类代码,不过都是用传统的file标签,今天整理一个好用的插件Uploadify..都做了一些注释,一看便知. 可以去官网下载最新的:Uploadify下载地址:http://www.uploadify.com/download/ 1.引用文件 <link href="@Url.Content("~/Scripts/uploadify/uploadify.css")" rel="stylesheet"

jquery uploadify上传文件时报HTTP401错误

1.http 401错误简单介绍 当用浏览器访问一个服务地址时,会向服务发送一个http请求,服务变会处理请求,并给浏览器返回一个状态码,每个状态码代表的不同的服务响应状态.     比如:200 代码响应成功,404资源未找到 这里的401就代表没有访问资源的权限状态. 2.401错误分析原因 正如上面介绍的一样,uploadify发出了上传请求,但服务端认为请求没有相应的权限. 现在大多数的身份验证用的是session,如果浏览器的cookie是打开的,那么sessionid的值是存在coo

jquery.uploadify上传文件配置详解(asp.net mvc)

页面源码: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>jquery upload上传文件(asp.net mvc)配置</title> <script src="Resources/jquery.js"

SpringMVC+jquery.uploadify 上传文件

前言 以前用Asp.net MVC+uploadify上传文件,最近学习SpringMVC,所以就用SpringMVC+uploadify做个上传文件的demo. 刚开始用form表单的方式提交,在Controller Action中用@RequestParam MultipartFile file就能拿到上传文件信息.后我直接使用uploadify的方式上传,接口没有做任何调整,上传的过程中报http400, 客户端的请求不符合接口的要求,表单post提交时报文参数是以Form Data方式,

Uploadify 上传文件插件详解

Uploadify是JQuery的一个上传插件,实现的效果非常不错,带进度显示.不过官方提供的实例时php版本的,本文将详细介绍Uploadify在Aspnet中的使用,您也可以点击下面的链接进行演示或下载. •官方下载 •官方文档 •官方演示 <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Uploadify</title&g

jQuery Uploadify上传插件

jQuery Uploadify在ASP.NET MVC3中的使用 1.Uploadify简介 Uploadify是基于jQuery的一种上传插件,支持多文件.带进度条显示上传,在项目开发中常被使用. Uploadify官方网址:http://www.uploadify.com/ jQuery Uploadify上传插件

jQuery之批量上传文件插件之一

$("#uploader").plupload({     /*常规设置*/     runtimes:'html5,flash,silverlight,html4',     url:'hyzx/seller/commPicUpload.action',     /*最大文件限制b, kb, mb, gb, tb */     max_file_size:'1mb',     /*是否生成唯一文件名,如果为true会为上传的文件唯一的文件名.*/     unique_names:t