Samuel Jackson Samuel Jackson - 4 months ago 15
Javascript Question

How can I trigger the error event in DropZone using PHP?

In dropzone.js , there is an event

, however I can not find any documentation on how to trigger this from PHP.

I have tried sending various header() responses from PHP including, 404, 500, 503, and so on yet this event has not fired.

What I am looking to do, is the server checks the mime to see if it is valid, and if it is not valid, I discard the file, and ideally -- return an error so that dropzone can respond accordingly.

From the javascript side, I have tried the following :

.on("complete", function(file,response) {

.on("error", function(file,response) {

.on("success", function(file,response) {

... however,
is undefined, even if i return JSON or plain text from the php script. It doesn't appear that dropzone.js supports getting the full server response or at least it doesn't elevate it to the custom handler. The ONLY place I have seen any reference to passing a second param on events is here on SO in other questions that are not directly asking this question.

There must be a way to get the server response (as I have done in the past with other uploader javascript such as jQuery POST, and jqUpload, and so on). It seems rather silly that I can't trigger a command to signal the upload failed -- even if the file transfer completed -- as it still needs to wait on the script for a response. --- This means I am likely overlooking something, which is why I am calling for assistance as their documentation reveals absolutely nothing with regards to how a server should respond --- language irrelevant, however in my case, I am using PHP.

Thanks in advance.

header('HTTP/1.1 500 Internal Server Error');
header('Content-type: text/plain');
$msg = "Your error message here.";

NOTE: Do not redirect user else it wont run "exit($msg)"

<script type="text/javascript">
            $( document ).ready(function() {

Dropzone.options.dropzone = {

    maxFilesize: 10, 
    init: function() {
      this.on("uploadprogress", function(file, progress) {
        console.log("File progress", progress);


Thats it!. It should work