uploadify多文件上傳參數(shù)設(shè)置技巧
比起swfupload,uploadify插件配置使用都更簡單,只是剛加載的時(shí)候稍微慢了一秒左右.
廢話不多說了,直接給大家貼代碼了。
<html xmlns=”http://www.w3.org/1999/xhtml”> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ /> <title>php jquery uploadify多文件上傳</title> <link href=”css/default.css” rel=”stylesheet” type=”text/css” /> <link href=”css/uploadify.css” rel=”stylesheet” type=”text/css” /> <script type=”text/javascript” src=”js/jquery-1.3.2.min.js”></script> <script type=”text/javascript” src=”js/swfobject.js”></script> <script type=”text/javascript” src=”js/jquery.uploadify.v2.1.0.min.js”></script> <script type=”text/javascript”> $(document).ready(function() { $(“#fileInput2″).uploadify({ ‘uploader': ‘js/uploadify.swf',//所需要的flash文件 ‘cancelImg': ‘cancel.png',//單個(gè)取消上傳的圖片 'script': ‘js/uploadify.php',//實(shí)現(xiàn)上傳的程序 ‘folder': ‘uploads',//服務(wù)端的上傳目錄 //'auto': true,//自動(dòng)上傳 ‘multi': true,//是否多文件上傳 //'checkScript': ‘js/check.php',//驗(yàn)證 ,服務(wù)端的 ‘displayData': 'speed',//進(jìn)度條的顯示方式 //'fileDesc': ‘Image(*.jpg;*.gif;*.png)',//對(duì)話框的文件類型描述 //'fileExt': ‘*.jpg;*.jpeg;*.gif;*.png',//可上傳的文件類型 //'sizeLimit': 999999 ,//限制上傳文件的大小 //'simUploadLimit' :3, //并發(fā)上傳數(shù)據(jù) //'queueSizeLimit' :5, //可上傳的文件個(gè)數(shù) //'buttonText' :'文件上傳',//通過文字替換鈕扣上的文字 ‘buttonImg': ‘css/images/browseBtn.png',//替換上傳鈕扣 ‘width': 80,//buttonImg的大小 ‘height': 24,// ‘rollover': true,//button是否變換 onComplete: function (evt, queueID, fileObj, response, data) { //alert(“Successfully uploaded: “+fileObj.filePath); //alert(response); getResult(response);//獲得上傳的文件路徑 } //onError: function(errorObj) { // alert(errorObj.info+” “+errorObj.type); //} }); }); </script> <script type=”text/javascript”> function getResult(content){ //通過上傳的圖片來動(dòng)態(tài)生成text來保存路徑 var board = document.getElementById(“divTxt”); board.style.display=””; var newInput = document.createElement(“input”); newInput.type = “text”; newInput.size = “45″; newInput.name=”myFilePath[]“; var obj = board.appendChild(newInput); var br= document.createElement(“br”); board.appendChild(br); obj.value=content; } </script> </head> <body> <fieldset style=”border: 1px solid #CDCDCD; padding: 8px; padding-bottom:0px; margin: 8px 0″> <legend> <strong> 多文件上傳</strong></legend> <div> <input id=”fileInput2″ name=”fileInput2″ type=”file” /> <input type=”button” value=”確定上傳” onclick=”javascript:$(‘#fileInput2′).uploadifyUpload();”> || <a href=”javascript:$(‘#fileInput2′).uploadifyClearQueue();”>清除上傳列表</a></div> <p></p> </fieldset> <FORM name=”form2″ METHOD=POST ACTION=”db.php”> <div id=”divTxt” style=”display:none”><span style=”color:red”><strong>已經(jīng)上傳的圖片有:</strong></span& gt;<br></div><br> <INPUT TYPE=”submit” value=”提 交”> </FORM> </body> </html>
ps:uploadify插件實(shí)現(xiàn)多個(gè)圖片上傳并預(yù)覽
使用uploadify插件可方便實(shí)現(xiàn)圖片上傳功能。兼容ie6、ie7。
上傳成功之后使用插件的回調(diào)函數(shù)讀取json數(shù)據(jù),根據(jù)url實(shí)現(xiàn)圖片預(yù)覽。
效果圖:
點(diǎn)擊瀏覽文件上傳圖片,圖片依次在右側(cè)顯示預(yù)覽效果。
實(shí)現(xiàn):
json數(shù)據(jù)格式如下:
頁面代碼如下:
注:需要引用jQuery.js、uploadify.js、uploadify文件。。uploadify文件下載地址:http://www.uploadify.com/download/
<html> <head> <script type="text/javascript" src="static/js/jquery.js">"></script> <script type="text/javascript" src="static/js/jquery.select.js">"></script> </head> <body> <div class="file-box"> <div id="divPreview"> <span style="float:left">(最多可上傳五張圖片)</span> </div> <input type="file" name="file" class="file" id="fileField" /> <input type="hidden" name="hash" id="hash" value="xoxo"/> </div> <script> $(function() { $("#fileField").uploadify({ 'height' : 30, 'swf' : '<?php echoYii::app()->request->baseUrl ?>/static/uploadify/uploadify.swf?var='+(newDate()).getTime(), 'uploader' :'index.php?r=upload/uploadimage', 'width' : 120, 'onUploadSuccess' : function(file, data, response) { var info = eval("("+data+")"); if(info.err==1){alert(info.msg);} //如果圖片過大或者格式錯(cuò)誤彈出錯(cuò)誤信息 else{ $("#divPreview").append($("<img src='" + info.img + "'/>")); $("#divPreview").append($("<input type='hidden' name='imgId[]' value='" + info.imgId + "'/>")); } }, 'buttonText' : '瀏覽文件', 'uploadLimit' : 5, //上傳最多圖片張數(shù) 'removeTimeout' : 1, 'preventCaching': true, //不允許緩存 'fileSizeLimit' : 4100, //文件最大 'formData' : { '<?php echosession_name();?>' : '<?php echosession_id();?>','hash':$("#hash").val() } //hash }); $("#SWFUpload_0").css({ //設(shè)置按鈕樣式,根據(jù)插件文檔進(jìn)行修改 'position' :'absolute', 'top': 20, 'left': 35, 'z-index' : 1 }); }); </script> </body> </html>
曾遇到問題:
ie、360瀏覽器中對(duì)json數(shù)據(jù)檢查比較嚴(yán)格,不允許最后一個(gè)“,”存在。其它瀏覽器不會(huì)報(bào)錯(cuò),需要注意。
- 詳解jQuery uploadify文件上傳插件的使用方法
- Javascript使用uploadify來實(shí)現(xiàn)多文件上傳
- uploadify java實(shí)現(xiàn)多文件上傳和預(yù)覽
- jQuery.uploadify文件上傳組件實(shí)例講解
- jQuery文件上傳控件 Uploadify 詳解
- ASP.NET多文件上傳控件Uploadify的使用方法
- ASP.NET文件上傳控件Uploadify的使用方法
- php+jQuery.uploadify實(shí)現(xiàn)文件上傳教程
- jQuery文件上傳插件Uploadify使用指南
- JavaScript Uploadify文件上傳實(shí)例
相關(guān)文章
JQuery中關(guān)于jquery.js與jquery.min.js的比較探討
jquery-1.4.2.min.js是優(yōu)化的,而query-1.4.2.js是易于開發(fā)著閱讀的,具體詳解祥看本文,希望對(duì)你有所幫助2013-05-05jQuery簡單實(shí)現(xiàn)列表隱藏和顯示效果示例
這篇文章主要介紹了jQuery簡單實(shí)現(xiàn)列表隱藏和顯示效果,結(jié)合實(shí)例形式分析了jQuery中slideToggle動(dòng)態(tài)操作頁面元素切換的相關(guān)技巧,需要的朋友可以參考下2016-09-09jQuery實(shí)現(xiàn)可關(guān)閉固定于底(頂)部的工具條菜單效果
這篇文章主要介紹了jQuery實(shí)現(xiàn)可關(guān)閉固定于底(頂)部的工具條菜單效果,可實(shí)現(xiàn)固定位置顯示及響應(yīng)鼠標(biāo)點(diǎn)擊展開與關(guān)閉的功能,涉及jQuery響應(yīng)鼠標(biāo)事件動(dòng)態(tài)操作頁面元素樣式屬性的相關(guān)技巧,需要的朋友可以參考下2015-11-11jquery實(shí)現(xiàn)簡單合攏與展開網(wǎng)頁面板的方法
這篇文章主要介紹了jquery實(shí)現(xiàn)簡單合攏與展開網(wǎng)頁面板的方法,通過簡單的jquery頁面元素樣式操作實(shí)現(xiàn)展開與合攏面板的功能,非常簡單實(shí)用,需要的朋友可以參考下2015-09-09Jquery動(dòng)態(tài)添加及刪除頁面節(jié)點(diǎn)元素示例代碼
這篇文章主要介紹了Jquery如何動(dòng)態(tài)添加及刪除頁面節(jié)點(diǎn)元素,示例代碼如下,需要的朋友不要錯(cuò)過2014-06-06