jquery插件uploadify實(shí)現(xiàn)帶進(jìn)度條的文件批量上傳
有時(shí)項(xiàng)目中需要一個(gè)文件批量上傳功能時(shí),個(gè)人認(rèn)為uploadify是快速簡(jiǎn)便的解決方案,分享給大家供大家參考,具體如下
先上效果圖:
具體代碼如下:
在頁(yè)面中如下
完整頁(yè)面代碼
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>文件批量上傳Demo</title> <!--引入Jquery--> <script src="js/jquery-1.11.3.min.js"></script> <!--引入uploadify--> <script type="text/javascript" src="uploadify/jquery.uploadify.js"></script> <link type="text/css" href="uploadify/uploadify.css" rel="stylesheet" /> <script type="text/javascript"> $(function () { var guid = '<%=Request["guid"] %>'; var type = '<%=Request["type"] %>'; if (guid == null || guid == "") { guid = newGuid(); } if (type != null) { type = type + '/'; } $('#file_upload').uploadify({ 'swf': 'uploadify/uploadify.swf', //FLash文件路徑 'buttonText': '瀏 覽', //按鈕文本 'uploader': 'uploadhandler.ashx?guid=' + guid, //處理ASHX頁(yè)面 'formData': { 'folder': 'picture', 'isCover': 1 }, //傳參數(shù) 'queueID': 'fileQueue', //隊(duì)列的ID 'queueSizeLimit': 10, //隊(duì)列最多可上傳文件數(shù)量,默認(rèn)為999 'auto': false, //選擇文件后是否自動(dòng)上傳,默認(rèn)為true 'multi': true, //是否為多選,默認(rèn)為true 'removeCompleted': true, //是否完成后移除序列,默認(rèn)為true 'fileSizeLimit': '0', //單個(gè)文件大小,0為無(wú)限制,可接受KB,MB,GB等單位的字符串值 'fileTypeDesc': 'All Files', //文件描述 'fileTypeExts': '*.*', //上傳的文件后綴過(guò)濾器 'onQueueComplete': function (queueData) { //所有隊(duì)列完成后事件 alert("上傳完畢!"); }, 'onError': function (event, queueId, fileObj, errorObj) { alert(errorObj.type + ":" + errorObj.info); }, 'onUploadStart': function (file) { }, 'onUploadSuccess': function (file, data, response) { //一個(gè)文件上傳成功后的響應(yīng)事件處理 //var data = $.parseJSON(data);//如果data是json格式 //var errMsg = ""; } }); }); function newGuid() { var guid = ""; for (var i = 1; i <= 32; i++) { var n = Math.floor(Math.random() * 16.0).toString(16); guid += n; if ((i == 8) || (i == 12) || (i == 16) || (i == 20)) guid += "-"; } return guid; } //執(zhí)行上傳 function doUpload() { $('#file_upload').uploadify('upload', '*'); } </script> </head> <body> <form id="form1" runat="server" enctype="multipart/form-data"> <div id="fileQueue" class="fileQueue"></div> <div> <input type="file" name="file_upload" id="file_upload" /> <p> <input type="button" class="shortbutton" id="btnUpload" onclick="doUpload()" value="上傳" /> <input type="button" class="shortbutton" id="btnCancelUpload" onclick="$('#file_upload').uploadify('cancel')" value="取消" /> </p> <div id="div_show_files"></div> </div> </form> </body> </html>
UploadHandler.ashx代碼:
using System; using System.Web; using System.IO; public class UploadHandler : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; context.Request.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); context.Response.Charset = "UTF-8"; if (context.Request.Files.Count > 0) { #region 獲取上傳路徑 string uploadFolder = GetUploadFolder(); #endregion if (System.IO.Directory.Exists(uploadFolder)) {//如果上傳路徑存在 HttpPostedFile file = context.Request.Files["Filedata"]; string filePath = Path.Combine(uploadFolder, file.FileName); file.SaveAs(filePath); context.Response.Write("0"); } else { context.Response.Write("2"); } } } public bool IsReusable { get { return false; } } /// <summary> /// 返回不帶后綴的文件名 /// </summary> /// <param name="fileName"></param> /// <returns></returns> public static string GetFirstFileName(string fileName) { return Path.GetFileNameWithoutExtension(fileName); } /// <summary> /// 獲取上傳目錄 /// </summary> /// <returns></returns> public static string GetUploadFolder() { string rootPath = HttpContext.Current.Server.MapPath("~"); return Path.Combine(rootPath, "test"); } }
文件上傳.NET默認(rèn)有大小限制,像IIS限制的30M默認(rèn)請(qǐng)求大小。如果不想修改IIS,又想突破這個(gè)大小的限制,比如上傳1GB大小的文件。
這是修改Web.config即可實(shí)現(xiàn)。
<?xml version="1.0" encoding="utf-8"?> <!-- --> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> <httpRuntime maxRequestLength="1073741824"/> </system.web> <!--用于設(shè)置文件上傳的最大允許大小(單位:bytes)--> <system.webServer> <security> <requestFiltering> <!--修改服務(wù)器允許最大長(zhǎng)度(1GB)--> <requestLimits maxAllowedContentLength="1073741824"/> </requestFiltering> </security> </system.webServer> </configuration>
希望本文所述對(duì)大家學(xué)習(xí)javascript程序設(shè)計(jì)有所幫助。
- jQuery.uploadify文件上傳組件實(shí)例講解
- jQuery文件上傳控件 Uploadify 詳解
- php+jQuery.uploadify實(shí)現(xiàn)文件上傳教程
- jQuery文件上傳插件Uploadify使用指南
- Jquery Uploadify多文件上傳帶進(jìn)度條且傳遞自己的參數(shù)
- 基于Jquery插件Uploadify實(shí)現(xiàn)實(shí)時(shí)顯示進(jìn)度條上傳圖片
- 解決jQuery上傳插件Uploadify出現(xiàn)Http Error 302錯(cuò)誤的方法
- jQuery uploadify在谷歌和火狐瀏覽器上傳失敗的解決方案
- 解決jQuery uploadify在非IE核心瀏覽器下無(wú)法上傳
- firefox瀏覽器用jquery.uploadify插件上傳時(shí)報(bào)HTTP 302錯(cuò)誤
- 詳解jQuery uploadify文件上傳插件的使用方法
相關(guān)文章
jQuery超簡(jiǎn)單遮罩層實(shí)現(xiàn)方法示例
這篇文章主要介紹了jQuery超簡(jiǎn)單遮罩層實(shí)現(xiàn)方法,結(jié)合實(shí)例形式詳細(xì)分析了jQuery遮罩層相關(guān)屬性樣式動(dòng)態(tài)控制操作技巧,需要的朋友可以參考下2018-09-09jQuery EasyUI API 中文文檔 - ValidateBox驗(yàn)證框
jQuery EasyUI API 中文文檔 - ValidateBox驗(yàn)證框,使用jQuery EasyUI的朋友可以參考下。2011-10-10jQuery實(shí)現(xiàn)一個(gè)簡(jiǎn)單的驗(yàn)證碼功能
今天給大家分享一個(gè)基于jquery實(shí)現(xiàn)的簡(jiǎn)單驗(yàn)證碼功能,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的的朋友參考下吧2017-06-06一款jquery特效編寫(xiě)的大度寬屏焦點(diǎn)圖切換特效的實(shí)例代碼
焦點(diǎn)圖顯示區(qū)域有固定的寬度,當(dāng)前顯示寬度之外是一個(gè)半透明層顯示的其它的焦點(diǎn)圖片,最好的是,此特效兼容ie6以及其它瀏覽器。2013-08-08jQuery實(shí)現(xiàn)簡(jiǎn)單復(fù)制json對(duì)象和json對(duì)象集合操作示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)簡(jiǎn)單復(fù)制json對(duì)象和json對(duì)象集合操作,結(jié)合實(shí)例形式分析了jQuery使用extend方法操作json對(duì)象與json對(duì)象集合復(fù)制相關(guān)技巧,需要的朋友可以參考下2018-07-07CSS+jQuery實(shí)現(xiàn)簡(jiǎn)單的折疊菜單
這篇文章主要介紹了CSS+jQuery實(shí)現(xiàn)簡(jiǎn)單的折疊菜單的代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧2016-12-12