• 7

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

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

In dropzone.js , there is an event error, 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, response 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 won't 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);


That's it! It should work.

  • 13
Reply Report

If you send any non-200 response header Dropzone will detect it as an error and fire the error(file, response) event. The error info can go in as JSON and is accessible via response.your_msg_variable

Note that just printing response won't show anything useful as it's an object, you can use console.log(JSON.stringify(responseText, null, 4));

This will pretty print the object upto 4 levels down

  • 2
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions