来自 PHP 的 Dropzone debug 和 ajax 消息


Dropzone debug and ajax messages from PHP

我正在使用最新的 Dropzone.js 版本 3.7.1 和 PHP 脚本将文件上传到服务器

我想将消息返回到图像上的拖放区区域所以我退出

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

这将在图像上显示一般的拖放区错误但是如果我使用

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

我收到"来自服务器的 JSON 响应无效"。

如果我使用

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

我得到"[对象对象]"

拖放区是将文件上传为数组还是单个文件?

您可以将响应内容类型设置为text/plain并仅发送消息,或者将内容类型设置为application/json并发送{"error": "message"}

在这两种情况下,您都需要发送错误标头,否则 Dropzone 不会将响应解释为错误:

header('HTTP/1.1 500 Internal Server Error');
header('Content-type: text/plain');
exit("My error");