Dropzone JS添加删除按钮

时间:2015-04-15 03:25:07

标签: php jquery dropzone.js

对不起来自dropzone的新手, 我需要在文件成功上传后从Dropzone JS创建删除按钮 我尝试使用

if(typeof Dropzone != 'undefined')
        {

            Dropzone.autoDiscover = true;

            $(".dropzone[action]").each(function(i, el)
            {
                $(el).dropzone();
            });
            Dropzone.createElement("<button>Remove file</button>");     

        }

删除按钮仍未显示在tumbnails的底部。 我的页面:

<form action="data/upload-file.php" class="dropzone"></form>

我的PHP UPLOAD文件

<?php

header('Content-Type: application/json');

#$errors = mt_rand(0,100)%2==0; // Random response (Demo Purpose)
$errors = false;


$resp = array(
);

# Normal Response Code
if(function_exists('http_response_code'))
    http_response_code(200);

# On Error
if($errors)
{
    if(function_exists('http_response_code'))
        http_response_code(400);

    $resp['error'] = "Couldn't upload file, reason: ~";
}

echo json_encode($resp);

1 个答案:

答案 0 :(得分:4)

我成功了,谢谢@pddong 通过添加&#34; addRemoveLinks:true&#34;

if(typeof Dropzone != 'undefined')
    {
        Dropzone.autoDiscover = false;
        var myDropzone = new Dropzone("#myDropzone", {
        url: "data/upload-file.php",
        maxFileSize: 50,
        acceptedFiles: ".pdf",
        addRemoveLinks: true,
        //more dropzone options here
    });

    }
};

,页面就像这样

<form action="data/upload-file.php" class="dropzone" id="myDropzone"></form>