【问题标题】:How to load the file data to download template on page refresh in blueimp jquery file upload如何在blueimp jquery文件上传中加载文件数据以在页面刷新时下载模板
【发布时间】:2014-03-11 23:53:53
【问题描述】:

类似这个问题:https://github.com/blueimp/jQuery-File-Upload/issues/1466

每次页面加载时,我如何默认加载带有文件数据的下载模板?谷歌似乎没有答案。

谢谢。

【问题讨论】:

  • 初始问题中的链接已失效

标签: jquery file-upload blueimp multi-upload


【解决方案1】:

使用此代码并检查您的 url 以获取显示图像。就我而言,我使用的是“/Upload/UploadHandler.ashx”。

这段代码你放在 main.js 中。

$(function () {
        'use strict';

        // Initialize the jQuery File Upload widget:
        $('#fileupload').fileupload();

        $('#fileupload').fileupload('option', {
            maxFileSize: 500000000,
            resizeMaxWidth: 1920,
            resizeMaxHeight: 1200
        });

        // Enable iframe cross-domain access via redirect option:
        $('#fileupload').fileupload(
            'option',
            'redirect',
            window.location.href.replace(
                /\/[^\/]*$/,
                '/cors/result.html?%s'
            )
        );

        // Load existing files:
        $('#fileupload').addClass('fileupload-processing');
        $.ajax({
            // Uncomment the following to send cross-domain cookies:
            //xhrFields: {withCredentials: true},
            url: "/Upload/UploadHandler.ashx",
            dataType: 'json',
            context: $('#fileupload')[0]
        }).always(function () {
            $(this).removeClass('fileupload-processing');
        }).done(function (result) {
            $(this).fileupload('option', 'done')
                .call(this, $.Event('done'), { result: result });
        });
    });

【讨论】:

【解决方案2】:

我只是用另一种愚蠢的方式做到了。不确定是否是真正的解决方案,但它暂时解决了我的问题。

我做了如下,

  1. 如果照片数据在表格中可用,请检查数据库。
  2. 如果返回 true,我将显示上传模板(从 blueimp 中的默认脚本复制)

例如:

<?php 
                if($imageResults != false){                      
                    //show image
                    while($imageRow=mysqli_fetch_array($imageResults))
                    {
                        echo '<div class="template-download fade in" style="float:left; display:inline-block; margin: 0 10px 10px;">
    <div>
        <span class="preview">

                <a href="/upload/server/php/files/"'.$imageRow['name'].'" title="'.$imageRow['name'].'" download="'.$imageRow['name'].'" data-gallery=""><img src="/upload/server/php/files/thumbnail/'.$imageRow['name'].'"></a>

        </span>
    </div>
    <div>

            <button class="btn btn-danger delete" data-type="POST" data-url="/upload/server/php/?file='.$imageRow['name'].'&amp;_method=DELETE">
                <i class="glyphicon glyphicon-trash"></i>
                <span>Delete</span>
            </button>
            <input type="checkbox" name="delete" value="1" class="toggle">

    </div>
</div>';
                    }
                }
                //else leave blank
            ?>

默认情况下,它将加载带有文件的下载模板。

【讨论】:

    猜你喜欢
    • 2016-09-21
    • 1970-01-01
    • 1970-01-01
    • 2019-01-31
    • 2016-07-25
    • 1970-01-01
    • 2020-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多