Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropzone debug and ajax messages from PHP

I'm using latest Dropzone.js release 3.7.1 and PHP script to upload file to server

I'm would like to get message back to drop zone area, on image so i exit with

header('HTTP/1.1 500 Internal Server Error');
header('Content-Type: application/json');
exit();

this display a generic dropzone error on image but if i use

header('HTTP/1.1 500 Internal Server Error');
header('Content-Type: application/json');
exit("My error");

I get "Invalid JSON response from server."

if i use

header('HTTP/1.1 500 Internal Server Error');
header('Content-type: application/json');
exit(json_encode(array('message' => '$msg', code => 500)));

i get "[object Object]"

Does drop zone pass file upload as an array or as a single file?

like image 339
al404IT Avatar asked Nov 15 '13 09:11

al404IT


1 Answers

You can set the response Content-Type to text/plain and just send the message, or set the Content-Type to application/json and send {"error": "message"}.

In both cases you need to send an error header, otherwise Dropzone will not interpret the response as an error:

header('HTTP/1.1 500 Internal Server Error');
header('Content-type: text/plain');
exit("My error");
like image 183
enyo Avatar answered Nov 15 '22 09:11

enyo