我有一个在TinyMCE中工作的图像处理程序:
images_upload_handler: function (blobInfo, success, failure) {
var xhr, formData;
xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.open('POST', 'queries/editorImageUpload.php');
xhr.onload = function() {
var json;
if (xhr.status != 200) {
failure('HTTP Error: ' + xhr.status);
return;
}
console.log(xhr.response);
//your validation with the responce goes here
success(xhr.response);
};
formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
xhr.send(formData);
}
我想将另一段数据发送到'editorImageUpload'页面,该页面是将图像添加到的目录的名称。但我不确定如何添加它。我会将它添加到追加行吗?:
formData.append('file','directoryNameGoesHere', blobInfo.blob(), blobInfo.filename());
或者这会搞乱追加的结构。谢谢。
答案 0 :(得分:1)
如果您想要添加更多值来发送,只需像使用Blob一样追加它们
formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
formData.append('directory','path/to/whereever');
然后阅读$_POST['directory']
获取值
答案 1 :(得分:0)
请注意,最后一个字段必须是文件本身。因此,在文件之前添加其他任何字段。
formData.append('directory','path/to/whereever');
formData.append('file', blobInfo.blob(), blobInfo.filename());