相關(guān)關(guān)鍵詞
關(guān)于我們
最新文章
- PHP中opcode緩存簡(jiǎn)單用法分析
- thinkPHP控制器變量在模板中的顯示方法示例
- PHP move_uploaded_file() 函數(shù)(將上傳的文件移動(dòng)到新位置)
- dirname(__FILE__)的含義和應(yīng)用說(shuō)明
- thinkPHP5框架實(shí)現(xiàn)分頁(yè)查詢功能的方法示例
- PHP中單雙號(hào)與變量
- PHP獲得當(dāng)日零點(diǎn)時(shí)間戳的方法分析
- Laravel ORM對(duì)Model::find方法進(jìn)行緩存示例詳解
- PHP讀寫(xiě)文件高并發(fā)處理操作實(shí)例詳解
- 【CLI】利用Curl下載文件實(shí)時(shí)進(jìn)度條顯示的實(shí)現(xiàn)
PHP + plupload.js實(shí)現(xiàn)多圖上傳并顯示進(jìn)度條加刪除實(shí)例代碼
PHP + plupload.js JS插件實(shí)現(xiàn)多圖上傳并顯示進(jìn)度條加刪除實(shí)例,廢話不多說(shuō),直接上代碼
HTML代碼:
<!DOCTYPE html> <head> <meta charset="utf-8" /> <meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"> <title>多圖上傳</title> <script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript" src="plupload.full.min.js"></script> </head> <body> <style type="text/css"> *{ margin:0px; padding:0px; font-family:Microsoft Yahei; box-sizing:border-box; -webkit-box-sizing:border-box;} .demo{max-width:640px; margin:0 auto; min-width:320px;} .ul_pics{ float:left;} .ul_pics li{float:left; margin:0px; padding:0px; margin-left:5px; margin-top:5px; position:relative; list-style-type:none; border:1px solid #eee; width:80px; height:80px;} .ul_pics li img{width:80px;height:80px;} .ul_pics li i{ position:absolute; top:0px; right:-1px; background:red; cursor:pointer; font-style:normal; font-size:10px; width:14px; height:14px; text-align:center; line-height:12px; color:#fff;} .progress{position:relative; margin-top:30px; background:#eee;} .bar {background-color: green; display:block; width:0%; height:15px; } .percent{position:absolute; height:15px; top:-18px; text-align:center; display:inline-block; left:0px; width:80px; color:#666; line-height:15px; font-size:12px; } .demo #btn{ width:80px; height:80px; margin-left:5px; margin-top:5px; border:1px dotted #c2c2c2; background:url(up.png) no-repeat center; background-size:30px auto; text-align:center; line-height:120px; font-size:30px; color:#666; float:left;} </style> <div class="demo"> <a href="javascript:void(0)" rel="external nofollow" id="btn"></a> <ul id="ul_pics" class="ul_pics clearfix"> </ul> </div> <script type="text/javascript"> var uploader = new plupload.Uploader({ //創(chuàng)建實(shí)例的構(gòu)造方法 runtimes: 'html5,flash,silverlight,html4', //上傳插件初始化選用那種方式的優(yōu)先級(jí)順序 browse_button: 'btn', // 上傳按鈕 url: "upimgs.php?get=upimg", //遠(yuǎn)程上傳地址 flash_swf_url: 'plupload/Moxie.swf', //flash文件地址 silverlight_xap_url: 'plupload/Moxie.xap', //silverlight文件地址 filters: { max_file_size: '10mb', //最大上傳文件大?。ǜ袷?00b, 10kb, 10mb, 1gb) mime_types: [ //允許文件上傳類(lèi)型 {title: "files", extensions: "jpg,png,gif"} ] }, multipart_params:{ }, //文件上傳附加參數(shù) file_data_name:"upimg", //文件上傳的名稱 multi_selection: false, //true:ctrl多文件上傳, false 單文件上傳 init: { FilesAdded: function(up, files) { //文件上傳前 if ($("#ul_pics").children("li").length > 5) { alert("您上傳的圖片太多了!"); uploader.destroy(); } else { var li = ''; plupload.each(files, function(file) { //遍歷文件 li += "<li id='" + file['id'] + "'><div class='progress'><span class='bar'></span><span class='percent'>上傳中 0%</span></div></li>"; }); $("#ul_pics").append(li); uploader.start(); } }, UploadProgress: function(up, file) { //上傳中,顯示進(jìn)度條 var percent = file.percent; $("#" + file.id).find('.bar').css({"width": percent + "%"}); $("#" + file.id).find(".percent").text("上傳中 "+percent + "%"); }, FileUploaded: function(up, file, info) { //文件上傳成功的時(shí)候觸發(fā) var data = eval("(" + info.response + ")"); $("#" + file.id).html("<img src='" + this.url + "'/><i onclick='delimg(this)'>x</i><input type='hidden' name='' value='"+ this.url +"'>"); }, Error: function(up, err) { //上傳出錯(cuò)的時(shí)候觸發(fā) alert("error"); } } }); uploader.init(); function delimg(o){ var src = $(o).prev().attr("src"); $.post("upimgs.php?get=delimg&imgurl="+src,function(data){ if(data==1){ $(o).parent().remove(); } }) } </script> </body> </html>