我有一个额外的输入文件,其他字段通过Dropzone发送,但是我无法获取输入文件的值。 我如何获取输入值并存储。 这是我的dropzone:
var myDropzone1 = new Dropzone("div#image-upload", {
url: "publicar/store",
autoProcessQueue:false,
parallelUploads: 100,
uploadMultiple: true,
maxFilesize:1,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
init: function(){
myDropzone1 = this; // closure
var btn1 = document.querySelector("#submit-all");
btn1.addEventListener("click", function(e) {
e.preventDefault();
e.stopPropagation();
});
this.on("sending", function(file, xhr, data) {
var year = $('#year').val();
data.append("principal",$('#principal')[0].files[0]);
data.append("year", year);
});
this.on("success", function(file, xhr){
alert(file.xhr.response);
$('#completoMsg').css("display", "block");
})
}
});
我的控制器保存数据和图像
$files1 = $request->file('principal');
foreach($files1 as $file1) {
/// RESIZE
$input['imagename'] = time() . "." . $file1->getClientOriginalExtension();
$anuncio->foto = $input['imagename'];
$img = Image::make($file1->getRealPath());
$img->fit(254, 190)->save($destinationPath.'/'. $input['imagename']);
}
$anuncio->save();