---
title: "jquery 文件上传插件Uploadify 初探"
author: "小码哥BASE64"
date: "2014-07-19T15:33:07Z"
tags: []
categories: ["Web前端"]
slug: "jquery-uploadify"
draft: false
lastmod: "2014-07-19T15:33:07Z"
id: 2093987
url: "https://coderbase64.iteye.com/blog/2093987"
---

最近使用了uploadify做文件上传,上传同时展示进度条，感觉简单方便，功能也叫完善，先记下来再说。

官方地址 http://www.uploadify.com/ 

提供了html5的版本和Flash的版本，html5的版本收费，所以使用的Flash版本，你懂的。。。

先来看下我的代码，看看uploadify使用有多简单、方便。。。

将下载的uploadify.zip解压，

![](http://dl2.iteye.com/upload/attachment/0099/3395/f3fda22e-086f-3a49-97a9-fd53f9e3e3e9.png)  
   
 

这个文件需要在页面引用，当然jquery是肯定不能少了，如下是文件上传的html页面：

&lt;html xmlns=*"http://www.w3.org/1999/xhtml"*&gt;

&lt;head&gt;

    &lt;title&gt;*Uploadify*&lt;/title&gt;

     &lt;link href=*"/js/jquery.uploadify-v2.1.0/uploadify.css"*     rel=*"stylesheet"* type=*"text/css"* &gt;&lt;/link&gt;

 

  &lt;script src=*"/js/jquery-1.9.1.min.js"*&gt;&lt;/script&gt;

 

    &lt;script type=*"text/javascript"*

     src=*"/js/jquery.uploadify-v2.1.0/swfobject.js"*&gt;&lt;/script&gt;

 

    &lt;script type=*"text/javascript"*

   src=*"/js/jquery.uploadify-v2.1.0/jquery.uploadify.js"*&gt;&lt;/script&gt;

 

    &lt;script type=*"text/javascript"*&gt;

        $(document).ready(**function**()

        {

            $("*#uploadify*").uploadify({

            'auto'     : **false**,//不自动上传

            'multi':**false**,//不支持多文件上传

                'uploader': '*/uploadify*',//文件上传地址，对应后台服务器的接受地址

                'swf':'/js/jquer*y.uploadify-v2.1.0/uploadify.s*wf',//这个是Flash的文件选择插件

                //上传成功后执行的方法

                'onUploadSuccess':**function**(file,data,response){

                alert(response);

                alert(data);

                }

            });

        }); 

    &lt;/script&gt;

 

&lt;/head&gt;

&lt;body&gt;

  &lt;!--   &lt;div id="fileQueue"&gt;&lt;/div&gt; --&gt;

    &lt;input type=*"file"* name=*"uploadify"* id=*"uploadify"* /&gt;

     &lt;p&gt;

      &lt;a href=*"javascript:$('#uploadify').*uploadify*('upload','\*')"*&gt;上传&lt;/a&gt;|

      &lt;a href=*"javascript:$('#uploadify').*uploadifyC*learQueue()"*&gt;取消上传&lt;/a&gt;

    &lt;/p&gt;

&lt;/body&gt;

&lt;/html&gt;

 

简单吧，只需要在页面有个file类型的input标签，在调用uploadify，就完事，uploadify就可以正常工作了。

现在我们来看看几个基本的参数都是什么意思：

auto   是否自动上传，自动上传是指选择文件后，必须要点上传按钮了

multi   是否可以同时选择多个文件

uploader   文件上传地址

swf   Flash插件地址

onUploadSuccess  上传成功后执行的方法,其中data为服务器返回的数据

 

更多配置请参见  http://www.uploadify.com/documentation/