我试图让用户编辑他们之前上传的文件。

我创建了一个脚本,该脚本返回与上载文件时生成的HTML相同的HTML。

function add_fineuploader_images () {
    $post_id = $_POST['post_id'];
    $media = get_attached_media( 'image', $post_id);
    if ($media) {
    foreach ($media as $image) {
    ?>
        <li class="qq-file-id-0 qq-upload-success" qq-file-id="0" data-id="<?php echo $image->ID; ?>">
            <span class="qq-upload-spinner-selector qq-upload-spinner qq-hide"></span>
            <img class="qq-thumbnail-selector" qq-max-size="100" qq-server-scale="" src="<?php echo wp_get_attachment_image( $image->ID, 'thumbnail' );?>">
            <span class="qq-edit-filename-icon-selector qq-edit-filename-icon"></span>
            <span class="qq-upload-file-selector qq-upload-file"><?php echo $image->post_title; ?></span>
            <input class="qq-edit-filename-selector qq-edit-filename" tabindex="0" type="text">
            <a class="qq-upload-cancel-selector qq-upload-cancel qq-hide" href="#">Cancel</a>
            <a class="qq-upload-retry-selector qq-upload-retry qq-hide" href="#">Retry</a>
            <a class="qq-upload-delete-selector qq-upload-delete" href="#">Delete</a>
            <a class="qq-upload-featured-selector qq-upload-set-featured" href="#">Set as featured</a>
            <span class="qq-upload-status-text-selector qq-upload-status-text"></span>
        </li>
    <?php
    }
}
exit();

}


在页面加载时,我打电话给AJAX Post将图像加载到页面中:

var post_id = $('#post_id').val();
    $.post(Ajax.ajaxurl, { action: 'add_fineuploader_images', post_id: post_id }, function(data) {
        console.log(data);
        $('.qq-upload-list').html(data);
    });


这创建了与通过FineUploader上传文件时相同的预览。

现在,我需要让FineUploader知道这些,以便DELETE和其他方法起作用。

我像这样初始化FineUploader:

 $("#fine-uploader").fineUploader({
  request: {
        endpoint: Ajax.ajaxurl,
        params: {
            action: 'attach_files',
            post_id: $('#post_id').val()
        }
    },
  deleteFile: {
        enabled: true,
        endpoint: Ajax.ajaxurl,
        method: 'POST'
    }
});


我应该如何重新初始化FineUploader?还是有更好的方法来做到这一点?

最佳答案

如果要显示上一会话中已上传的文件,请使用Initial File List feature。无需在这里重新发明轮子。如果您想重置Fine Uploader,请使用reset API method

我注意到您在问文档中涉及的许多问题。我鼓励您仔细研究existing documentationdemos,我们希望它们相当全面。

10-04 15:51