Home  >  Article  >  Backend Development  >  TP5 integrates webuploader to realize preview drag search and delete

TP5 integrates webuploader to realize preview drag search and delete

*文
*文Original
2018-01-03 10:46:192700browse

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="" />
                            <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(&#39;Uploadify/delupload&#39;)}",
            "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^=&#39;fileurl_tmp&#39;]").each(function(index,dom){
                    fileurl_tmp[index] = dom.value;
                 });    
            }else{
                fileurl_tmp = $("input[name^=&#39;fileurl_tmp&#39;]").val();    
            }
            eval(&#39;window.parent.&#39;+callback+&#39;(fileurl_tmp)&#39;);
            window.parent.layer.closeAll();
            return;
        }                     
        if(num > 1){
                var fileurl_tmp = "";
                $("input[name^=&#39;fileurl_tmp&#39;]").each(function(){
                    fileurl_tmp += &#39;<li rel="&#39;+ this.value +&#39;"><input class="input-text" type="text" name="{$info.input}[]" value="&#39;+ this.value +&#39;" /><a href="javascript:void(0);" onclick="ClearPicArr(\&#39;&#39;+ this.value +&#39;\&#39;,\&#39;\&#39;)">删除</a></li>&#39;;    
                });            
                $(window.parent.document).find("#{$info.input}").append(fileurl_tmp);
        }else{
                $(window.parent.document).find("#{$info.input}").val($("input[name^=&#39;fileurl_tmp&#39;]").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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn