


TP5 integrates webuploader to realize preview drag search and delete
This article mainly introduces an example of thinkphp5 integrating webuploader and encapsulating it into an upload component, which is provided for your reference. I hope to be helpful.
WebUploader is a simple modern file upload component developed by the Baidu WebFE (FEX) team based on HTML5 and supplemented by FLASH. It can give full play to the advantages of HTML5 in modern browsers without abandoning the mainstream IE browser. It uses the original FLASH runtime and is compatible with IE6+, iOS 6+, android 4+. The two sets of runtimes have the same calling method and can be selected by the user. The use of large file fragmentation and concurrent upload greatly improves file upload efficiency.
Recently, many browsers have been upgraded to fully support HTML5 and disabled flash. Many upload plug-ins require flash, such as uploadify used in our project. In the latest Google Firefox browser It is not compatible with the previous version, so I finally replaced it with webuploader, which feels very good and is compatible with both HTML5 and flash uploads. It also supports multi-part upload of large files. Interested friends can continue to optimize and improve. Take a few screenshots below to see the effect
#
<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="/static/imghwm/default1.png" data-src="/public/js/jquery-1.10.2.min.js" class="lazy" / alt="TP5 integrates webuploader to realize preview drag search and delete" > <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="/static/imghwm/default1.png" data-src="/public/js/jquery-1.10.2.min.js" class="lazy" / alt="TP5 integrates webuploader to realize preview drag search and delete" > <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" ></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>
Related recommendations :
Detailed explanation of how ThinkPHP generates and verifies verification codes
thinkphp5 Upload pictures And how to generate thumbnails
Detailed examples of thinkphp5 URL and routing functions
The above is the detailed content of TP5 integrates webuploader to realize preview drag search and delete. For more information, please follow other related articles on the PHP Chinese website!

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools
