本文主要介紹了thinkphp5整合webuploader封裝成上傳元件的實例,提供給大家參考。希望對大家有幫助。
WebUploader是由Baidu WebFE(FEX)團隊開發的一個簡單的以HTML5為主,FLASH為輔的現代檔案上傳元件。在現代的瀏覽器裡面能充分發揮HTML5的優勢,同時又不摒棄主流IE瀏覽器,沿用原來的FLASH運行時,兼容IE6+,iOS 6+, android 4+。兩套運作時,同樣的呼叫方式,可供用戶任意選用。採用大文件分片並發上傳,極大的提高了文件上傳效率。
最近很多瀏覽器升級全面支援html5,並且停用了flash,許多上傳外掛程式都需要用到flash,例如我們的專案中用到的uploadify,在最新Google火狐瀏覽下就相容不了,最後採取了webuploader替代,感覺非常不錯,並且同時兼容html5和flash上傳,還支持大文件分片上傳,有興趣的朋友可以繼續優化改善。下面截圖幾張圖看看效果
<html lang="zh-cn"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>文件管理</title> <link rel="stylesheet" type="text/css" href="/public/plugins/webuploader/webuploader.css"> <link rel="stylesheet" type="text/css" href="/public/plugins/webuploader/css/style.css"> </head> <body> <p class="upload-box"> <ul class="tabs"> <li class="checked" id="upload_tab">本地上传</li> <li id="manage_tab">在线管理</li> <li id="search_tab">文件搜索</li> </ul> <p class="container"> <p class="area upload-area area-checked" id="upload_area"> <p id="uploader"> <p class="statusBar" style="display:none;"> <p class="progress"> <span class="text">0%</span> <span class="percentage"></span> </p><p class="info"></p> <p class="btns"> <p id="filePicker2"></p><p class="uploadBtn">开始上传</p> <p class="saveBtn">确定使用</p> </p> </p> <p class="queueList"> <p id="dndArea" class="placeholder"> <p id="filePicker"></p> <p>或将文件拖到这里,本次最多可选{$info.num|default=1}个</p> </p> </p> </p> </p> <p class="area manage-area" id="manage_area"> <ul class="choose-btns"> <li class="btn sure checked">确定</li> <li class="btn cancel">取消</li> </ul> <p class="file-list"> <ul id="file_all_list"> <!--<li class="checked"> <p class="img"> <img src="" /> <span class="icon"></span> </p> <p class="desc"></p> </li>--> </ul> </p> </p> <p class="area search-area" id="search_area"> <ul class="choose-btns"> <li class="search"> <p class="search-condition"> <input class="key" type="text" /> <input class="submit" type="button" hidefocus="true" value="搜索" /> </p> </li> <li class="btn sure checked">确定</li> <li class="btn cancel">取消</li> </ul> <p class="file-list"> <ul id="file_search_list"> <!--<li> <p class="img"> <img src="" /> <span class="icon"></span> </p> <p class="desc"></p> </li>--> </ul> </p> </p> <p class="fileWarp" style="display:none;"> <fieldset> <legend>列表</legend> <ul> </ul> </fieldset> </p> </p> </p> <script type="text/javascript" src="/public/js/jquery-1.10.2.min.js"></script> <script type="text/javascript" src="/public/plugins/webuploader/webuploader.min.js"></script> <script type="text/javascript" src="/public/plugins/webuploader/upload.js"></script> <script> $(function(){ var config = { "swf":"/public/plugins/webuploader/Uploader.swf", "server":"{$info.upload}", "filelistPah":"{$info.fileList}", "delPath":"{:U('Uploadify/delupload')}", "chunked":false, "chunkSize":524288, "fileNumLimit":{$info.num|default=1}, "fileSizeLimit":209715200, "fileSingleSizeLimit":2097152, "fileVal":"file", "auto":true, "formData":{}, "pick":{"id":"#filePicker","label":"点击选择图片","name":"file"}, "thumb":{"width":110,"height":110,"quality":70,"allowMagnify":true,"crop":true,"preserveHeaders":false,"type":"image\/jpeg"} }; Manager.upload($.extend(config, {type : "Images"})); /*点击保存按钮时 *判断允许上传数,检测是单一文件上传还是组文件上传 *如果是单一文件,上传结束后将地址存入$input元素 *如果是组文件上传,则创建input样式,添加到$input后面 *隐藏父框架,清空列队,移除已上传文件样式*/ $(".statusBar .saveBtn").click(function(){ var callback = "{$info.func}"; var num = {$info.num|default=1}; var fileurl_tmp = []; if(callback != "undefined"){ if(num > 1){ $("input[name^='fileurl_tmp']").each(function(index,dom){ fileurl_tmp[index] = dom.value; }); }else{ fileurl_tmp = $("input[name^='fileurl_tmp']").val(); } eval('window.parent.'+callback+'(fileurl_tmp)'); window.parent.layer.closeAll(); return; } if(num > 1){ var fileurl_tmp = ""; $("input[name^='fileurl_tmp']").each(function(){ fileurl_tmp += '<li rel="'+ this.value +'"><input class="input-text" type="text" name="{$info.input}[]" value="'+ this.value +'" /><a href="javascript:void(0);" onclick="ClearPicArr(\''+ this.value +'\',\'\')">删除</a></li>'; }); $(window.parent.document).find("#{$info.input}").append(fileurl_tmp); }else{ $(window.parent.document).find("#{$info.input}").val($("input[name^='fileurl_tmp']").val()); } window.parent.layer.closeAll(); }); }); </script> </body> </html>
#相關推薦:
以上是TP5整合webuploader實作預覽拖曳搜尋刪除的詳細內容。更多資訊請關注PHP中文網其他相關文章!