如何在blueimp jquery文件上传页面刷新时加载文件数据到下载模板

时间:2014-02-13 08:14:25

标签: jquery file-upload blueimp multi-upload

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

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

感谢。

2 个答案:

答案 0 :(得分:1)

使用此代码并检查您的网址以查看显示图像。在我的情况下,我使用“/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 });
        });
    });

答案 1 :(得分:0)

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

我在下面做了什么,

  1. 检查数据库是否有表格中的照片数据。
  2. 如果返回true,我将显示上传模板(从blueimp中的默认脚本中复制)
  3. 例如:

    <?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
                ?>
    

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