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("plete", function(file,response) {
console.log(response);
}
.on("error", function(file,response) {
console.log(response);
}
.on("success", function(file,response) {
console.log(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 mand to signal the upload failed -- even if the file transfer pleted -- 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.
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("plete", function(file,response) {
console.log(response);
}
.on("error", function(file,response) {
console.log(response);
}
.on("success", function(file,response) {
console.log(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 mand to signal the upload failed -- even if the file transfer pleted -- 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.
Share Improve this question asked Sep 28, 2014 at 13:21 Kraang PrimeKraang Prime 10.5k11 gold badges64 silver badges130 bronze badges2 Answers
Reset to default 13<?php
header('HTTP/1.1 500 Internal Server Error');
header('Content-type: text/plain');
$msg = "Your error message here.";
exit($msg);
?>
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);
});
}
};
});
</script>
That's it! It should work.
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