Heim  >  Artikel  >  php教程  >  swfupload分享一段自定义的配置

swfupload分享一段自定义的配置

WBOY
WBOYOriginal
2016-06-07 11:40:171109Durchsuche

好看的swfupload多文件上传的小插件
初始化的样子
swfupload分享一段自定义的配置
选择文件的样子
swfupload分享一段自定义的配置
没有选择文件的提示
swfupload分享一段自定义的配置
提交表单时候的空验证
swfupload分享一段自定义的配置


以下是代码var CYSUPLOAD=[];<br> (function($) {<br> $.fn.cysupload = function(options) {<br>     var Idname = "";<br>     var Swfname= "";<br>     this.initswf = function(_obj){<br>             var ranNan = $.rand(999);<br>             Classname = "files_input";<br>              Idname = "files_input_"+ranNan;<br>              Swfname="Swfobj_"+ranNan;<br>         var html = "<input>";<br>             html+= "<i></i>";<br>         this.html(html);<br>         options.Classname = Classname;<br>         options.Idname    = Idname;<br>         options.Cobj=this;<br>         var settings_object=this.initOptions(options);<br>         if(typeof(settings_object)=="undefined"){<br>             settings_object = {button_placeholder_id:Swfname};<br>         }else{<br>             settings_object.button_placeholder_id=Swfname;<br>         }<br>         CYSUPLOAD[settings_object.cid] = new SWFUpload(settings_object);<br>         CYSUPLOAD[settings_object.cid].settings = settings_object;<br>         CYSUPLOAD[settings_object.cid].inputname = Idname;<br>         <br>     }<br>     <br>     <br>     this.initOptions = function(options){<br>         var settings_object = {//定义参数配置对象<br>                 upload_url : "http://www.daili.com/index.php/All/upload/upload",<br>                     flash_url : "/Public/plugin/swfupload/swfupload.swf",<br>                     file_post_name : "Filedata",<br>                     use_query_string : false,<br>                     requeue_on_error : false,<br>                     http_success : [201, 202],<br>                     assume_success_timeout : 0,<br>                     file_types : "*.jpg;*.gif;*.png;*.jpeg",<br>                     file_types_description: "网页图片选择",<br>                     file_size_limit : "2048",<br>                     file_upload_limit : 20,<br>                     file_queue_limit : 20,<br>                     debug : false,<br>                     prevent_swf_caching : false,<br>                     preserve_relative_urls : false,<br>                     //button_placeholder_id : "element_id",<br>                     button_image_url : "/Public/plugin/swfupload/upload.jpg",<br>                     button_width : 85,<br>                     button_height : 22,<br>                     button_window_align:"top",<br>                     button_action : SWFUpload.BUTTON_ACTION.SELECT_FILES,<br>                     //button_disabled : false,<br>                     button_cursor : SWFUpload.CURSOR.HAND,<br>                     button_window_mode : SWFUpload.WINDOW_MODE.TRANSPARENT,<br>                     swfupload_loaded_handler : swfupload_loaded_function,<br>                     file_dialog_start_handler : file_dialog_start_function,<br>                     file_queued_handler : file_queued_function,<br>                     file_queue_error_handler : file_queue_error_function,<br>                     file_dialog_complete_handler : file_dialog_complete_function,<br>                     upload_start_handler : upload_start_function,<br>                     upload_progress_handler : upload_progress_function,<br>                     upload_error_handler : upload_error_function,<br>                     upload_success_handler : upload_success_function,<br>                     upload_complete_handler : upload_complete_function,<br>                     upload_success_all:function(){}<br>             };<br>         var result=$.extend({},settings_object,options);<br>         return result;<br>     };<br>     this.initswf(this);<br> };<br> $.addAllParam=function(options,_callback){<br>     if($.jsonLength(options)>0){<br>         var len = $.getobjlength();<br>         for(var i=0;i<len></len>             var options = $.extend({},options,CYSUPLOAD[i].settings.post_params);<br>             CYSUPLOAD[i].setPostParams(options);<br>         }<br>     }<br>     if(typeof(_callback)=="function"){<br>         _callback();<br>     }<br> }<br> $.jsonLength=function(_json){<br>     var len = 0;<br>     for(p in _json){<br>         len++;<br>     }<br>     return len;<br> }<br> $.rand = function getRandom(n){<br>     function S4() {<br>        return (((1+Math.random())*0x10000)|0).toString(16).substring(1);<br>     }<br>     return (S4()+S4()+"_"+S4()+"_"+S4()+"_"+S4()+"_"+S4()+S4()+S4());<br> }<br> //type 1进度条模式,2提示模式<br> $.process=function(options){<br>     var settings_object={<br>             pcolor:"#CDFEAD",<br>             pbgcolor:"#47AE02",<br>             tcolor:"#D0EBFD",<br>             tbgcolor:"#055387",<br>             floatid:CYSUPLOAD[options.cid].settings.Idname,<br>             appendObj:CYSUPLOAD[options.cid].settings.Cobj,<br>             name:"fileprocess_"+options.cid,<br>             type:1,<br>             msg:"",<br>             process_tag:"/",<br>             process_bai:true,<br>             process_bytes:true,<br>             bytes_compeled:0,<br>             bytes_total:0,<br>             total_files:0,<br>             now_file_id:0,<br>             compele_files:0,<br>             select_files:0<br>     }<br>     settings_object=$.extend({},settings_object,options);<br>     var bgCLname = 'process_bg'+settings_object.cid;<br>     var qbgCLname= 'process_qbg'+settings_object.cid;<br>     var process_html="<div></div>";<br>     var process_bg  ="<div></div>";<br>     var process_qbg  ="<div></div>";<br>     if($("#"+settings_object.name).length>0){<br>         $("#"+settings_object.name).remove();<br>         if($("."+bgCLname).length>0||$("."+qbgCLname).length){<br>             $("."+bgCLname).remove();<br>             $("."+qbgCLname).remove();<br>         }<br>     }<br>     var apendObj = settings_object.appendObj;<br>     $(process_html).appendTo(apendObj);<br>     $(process_bg).appendTo(apendObj);<br>     $(process_qbg).appendTo(apendObj);<br>     apendObj.css({<br>         position:"relative"<br>     });<br>     var floatobj = $("#"+settings_object.floatid);<br>     var _w=floatobj.innerWidth();<br>     var _h=floatobj.innerHeight();<br>     var top=floatobj.css("border-top-width");<br>     var left=floatobj.css("border-left-width");<br>     if(settings_object.type==1){<br>         var _ts = settings_object.total_files;<br>         var _bc = settings_object.bytes_compeled;<br>         var _bt = settings_object.bytes_total;<br>         var _cf = settings_object.compele_files;<br>         <br>         var one_util_width = Math.ceil((_w*100)/(_ts*100));<br>         var now_width         = one_util_width*_cf;<br>         var next_width     = Math.ceil((_bc*100)/(_bt*100))*one_util_width;<br>         next_width = next_width+now_width;<br>         if(next_width>=_w){<br>             next_width=_w;<br>         }<br>         $("#"+settings_object.name).css({<br>             color:settings_object.pcolor,<br>             background:settings_object.pbgcolor,<br>             "text-align":"center",<br>             width:now_width+"px",<br>             height:_h+"px",<br>             "line-height":_h+"px",<br>             position:"absolute",<br>             top:top,<br>             left:left,<br>             "z-index":3<br>         });<br>         $("."+bgCLname).css({<br>             color:settings_object.pcolor,<br>             background:"#5B5A4E",<br>             "text-align":"center",<br>             width:_w+"px",<br>             height:_h+"px",<br>             "line-height":_h+"px",<br>             position:"absolute",<br>             top:top,<br>             left:left,<br>             "z-index":2<br>         });<br>         $("."+qbgCLname).css({<br>             color:settings_object.pcolor,<br>             background:"transparent",<br>             "text-align":"center",<br>             width:_w+"px",<br>             height:_h+"px",<br>             "line-height":_h+"px",<br>             position:"absolute",<br>             top:top,<br>             left:left,<br>             "z-index":4<br>         });<br>         settings_object.msg="";<br>         if(settings_object.process_bai){<br>             if(_ts>1){<br>                 var percent = (_cf*100)/(_ts*100)*100;<br>             }else{<br>                 var percent = (_bc*100)/(_bt*100)*100;<br>             }<br>             settings_object.msg+=parseFloat(percent).toFixed(2);<br>             settings_object.msg+=" %,";<br>             if((_cf+1)                 settings_object.msg+="正在上传第"+(_cf+1)+"个文件["+_bc+"/"+_bt+"]";<br>             }else{<br>                 settings_object.msg+="正在上传第"+(_cf)+"个文件["+_bc+"/"+_bt+"]";<br>             }<br>             if(_ts==(_cf+1)&&_bc==_bt){<br>                 settings_object.msg="已上传完毕!";<br>             }<br>         }<br>         $("#"+settings_object.name).stop(true,true).animate({width:next_width},300);<br>         $("."+qbgCLname).html(settings_object.msg);<br>         <br>     }else if(settings_object.type==2){<br>         $("#"+settings_object.name).css({<br>             color:settings_object.tcolor,<br>             background:settings_object.tbgcolor,<br>             "text-align":"center",<br>             width:_w+"px",<br>             height:_h+"px",<br>             "line-height":_h+"px",<br>             position:"absolute",<br>             top:top,<br>             left:left,<br>             "z-index":3<br>         });<br>         $("#"+settings_object.name).html(settings_object.msg);<br>     }<br> }<br> $.getobjlength=function(){<br>    var len = parseInt(CYSUPLOAD.length);<br>    return len;<br> };<br> <br> $._nullcheck=function(_index){<br>     if(CYSUPLOAD[_index].select_num=="0"||CYSUPLOAD[_index].select_num==0||typeof(CYSUPLOAD[_index].select_num)=="undefined"){<br>         var _msg = "亲爱的,至少放点东西在我里面";<br>         $.process({type:2,tcolor:"#FFB9B9",tbgcolor:"#990000",msg:_msg,cid:_index});<br>         return false;<br>     }else{<br>         return true;<br>     }<br> }<br> <br> $.nullcheck = function(_obj){<br>     var _null = true;<br>     if(_obj.length>0){<br>         _obj.each(function(i){<br>             if(!$._nullcheck(i)){<br>                 _null = false;<br>             }<br>         });<br>     }<br>     return _null;<br> }<br> <br> $.doUpload=function(){<br>     CYSUPLOAD[0].startUpload();<br> }<br> <br> $.errorMsg = function(code){<br>     if(code         return false;<br>     }else{<br>         return true;<br>     }<br> }<br> })(jQuery);<br> //确实是影片加载之后调用的<br> function swfupload_loaded_function(){<br>     <br> }<br> //弹出文件选择框之前的句柄捕获<br> function file_dialog_start_function(){<br>     CYSUPLOAD[this.settings.cid].cancelQueue();<br> }<br> <br> //队列句柄捕获,当一个文件被加入进去的事件时触发,多次调用!<br> function file_queued_function(file){<br>     <br> }<br> //当文件添加到上传队列失败时触发此事件,失败的原因可能是文件大小超过了你允许的数值、文件是空的或者文件队列已经满员了等。<br> function file_queue_error_function(file,errmsg){<br>     CYSUPLOAD[this.settings.cid].error=errmsg;<br>     var code = errmsg*-1;<br>     if(code==100){<br>         var _msg = "亲爱的,本插件只允许"+CYSUPLOAD[this.settings.cid].settings.file_queue_limit+"个同时插入哦!";<br>     }else if(code==130){<br>         var _msg = "亲爱的,本插件只允许图片文件的插入哦!";<br>     }else if(code==110){<br>         var _msg = "亲爱的,你放进人家那里的东西太大了";<br>     }else if(code==120){<br>         var _msg = "亲爱的,你的东西太小了,本插件没有感受到它的存在";<br>     }<br>     $.process({type:2,tcolor:"#FFB9B9",tbgcolor:"#990000",msg:_msg,cid:this.settings.cid});<br> }<br> //当文件选取完毕且选取的文件经过处理后(指添加到上传队列),会立即触发该事件。可以在该事件中调用this.startUpload()方法来实现文件的自动上传<br> //参数select_num指本次在文件选取框里选取的文件数量<br> //参数queued_num指本次被添加到上传队列的文件数量<br> //参数queued_total_num指当前上传队列里共有多少个文件(包括了本次添加进去的文件)<br> function file_dialog_complete_function(select_num,queued_num){<br>     CYSUPLOAD[this.settings.cid].select_num = select_num;<br>     if(select_num>0){<br>         var _msg = "选择了"+select_num+"个文件";<br>         $.process({type:2,select_files:select_num,msg:_msg,cid:this.settings.cid});<br>     }else{<br>         var _msg = "你没有选择任何文件!";<br>         $.process({type:2,tcolor:"#FFB9B9",tbgcolor:"#990000",select_files:select_num,msg:_msg,cid:this.settings.cid});<br>     }<br>     <br> }<br> //当文件即将上传时会触发该事件,该事件给了你在文件上传前的最后一次机会来验证文件信息、<br> //增加要随之上传的附加信息或做其他工作。可以通过返回false来取消本次文件的上传<br> function upload_start_function(file){<br>     <br> }<br> //该事件会在文件的上传过程中反复触发,可以利用该事件来实现上传进度条<br> //参数file为文件信息对象<br> //参数completebytes为当前已上传的字节数<br> //参数totalbytes为文件总的字节数<br> function upload_progress_function(file,completebytes,totalbytes){<br>     var status = CYSUPLOAD[this.settings.cid].getStats();<br>     var a1 = parseInt(status.files_queued);<br>     var a2 = parseInt(status.successful_uploads);<br>     var a3 = parseInt(status.upload_errors);<br>     var totalsfiles = a1+a2+a3;<br>     $.process({<br>         now_file_id:file.id,<br>         total_files:totalsfiles,<br>         compele_files:a2,<br>         bytes_compeled:completebytes,<br>         bytes_total:totalbytes,cid:this.settings.cid<br>     });<br> }<br> //文件上传被中断或是文件没有成功上传时会触发该事件。停止、取消文件上传或是在uploadStart事件中返回false都会引发这个事件,<br> //但是如果某个文件被取消了但仍然还在队列中则不会触发该事件<br> //参数file为文件信息对象<br> //参数error_code为错误代码,具体的可参照SWFUpload.UPLOAD_ERROR中定义的常量<br> function upload_error_function(file,error_code){<br>     <br> }<br> //当一个文件上传成功后会触发该事件<br> //参数file为文件信息对象<br> //参数server_data为服务器端输出的数据<br> function upload_success_function(file,server_data){<br>     if(typeof(CYSUPLOAD[this.settings.cid].settings.upload_success_one)=="function"){<br>         CYSUPLOAD[this.settings.cid].settings.upload_success_one(server_data);<br>     }<br> }<br> //当一次文件上传的流程完成时(不管是成功的还是不成功的)会触发该事件,该事件表明本次上传已经完成,<br> //上传队列里的下一个文件可以开始上传了。该事件发生后队列中下一个文件的上传将会开始<br> function upload_complete_function(file){<br>     var _index = this.settings.cid;<br>     if (this.getStats().files_queued === 0) {<br>         if(_index==($.getobjlength()-1)){<br>             upload_all_complete();<br>         }else{<br>             var _next = _index+1;<br>             CYSUPLOAD[_next].startUpload();<br>         }<br>     } else {    <br>         CYSUPLOAD[_index].startUpload();<br>     }<br> }<br> <br> //当所有文件都上传成功之后<br> function upload_all_complete(){<br>     if(typeof(CYSUPLOAD[0].settings.upload_success_all)=="function"){<br>         CYSUPLOAD[0].settings.upload_success_all();<br>     }<br> }

AD:真正免费,域名+虚机+企业邮箱=0元

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn