Javascript Laravel-Dropzone未上载所有文件
我正在使用Dropzone在Laravel中上载文件。这就是配置Javascript Laravel-Dropzone未上载所有文件,javascript,laravel,dropzone.js,Javascript,Laravel,Dropzone.js,我正在使用Dropzone在Laravel中上载文件。这就是配置 <script type="text/javascript"> Dropzone.options.dropzone = { maxFiles: 50, maxFilesize: 200, parallelUploads: 10, uploadMultiple: true, ad
<script type="text/javascript">
Dropzone.options.dropzone =
{
maxFiles: 50,
maxFilesize: 200,
parallelUploads: 10,
uploadMultiple: true,
addRemoveLinks: true,
autoProcessQueue:false,//the true is tried as well
acceptedFiles: ".jpeg,.jpg,.png,.gif",
success: function (file, response) {
console.log(response);
},
error: function (file, response) {
return false;
}
};
</script>
从我在它里面看到的声音来看,问题来自下面的dropzone.js
Dropzone.prototype.processQueue = function() {
var i, parallelUploads, processingLength, queuedFiles;
parallelUploads = this.options.parallelUploads;
processingLength = this.getUploadingFiles().length;
i = processingLength;
if (processingLength >= parallelUploads) {
return;
}
queuedFiles = this.getQueuedFiles();
if (!(queuedFiles.length > 0)) {
return;
}
if (this.options.uploadMultiple) {
return this.processFiles(queuedFiles.slice(0, parallelUploads - processingLength));
} else {
while (i < parallelUploads) {
if (!queuedFiles.length) {
return;
}
this.processFile(queuedFiles.shift());
i++;
}
}
};
如果我上传
20
文件console.log(queuedFiles.length)代码>显示20
和行console.log(i)
显示从1
到20
的计数器,但它仍然上载3或4个文件,而不是所有文件。我能做什么呢?现在,这段代码既有添加图像也有删除图像,它可以在来自后端的API调用和ajax调用上工作
var myDropzone = new Dropzone("div#dropzonePrescriptionImages", {
url: "/appointment/prescription_multiple_file",
// params: {
// _token: token,booking_id:booking_id,file_inc:file_inc,
// },
sending: function(file, xhr, formData) {
formData.append("file_inc", file_inc); //name and value
formData.append("booking_id", booking_id); //name and value
formData.append("_token",token);
},
maxFiles:5,
init: function() {
this.on("maxfilesexceeded", function(file){
this.removeFile(file);
alert("Maximum 5 photos are allowed...!");
});
this.on("addedfile", function (file) {
var removeButton = Dropzone.createElement("<button><i class='glyphicon glyphicon-trash'></i></button>");
var _this = this;
removeButton.addEventListener("click", function (e){
e.preventDefault();
e.stopPropagation();
_this.removeFile(file);
var i=0;
var found=0;
var len = Object.keys(files_array).length;
for(i=0;i<len;i++){
if(files_array.hasOwnProperty(i)){
if(files_array[i]['name'] == file.name){
$.ajax({
type: 'GET',
url:'/deletePrescriptionFiles',
dataType: 'json',
data:{path:files_array[i]['file_path']},
async:false
}).done(function(result1){
files_array[i]['file_path']=undefined;
files_array[i]['name']=undefined;
return;
});
found==1;
break;
}
if(found==1){
break;
}
}
if(found==1){
break;
}
}
$('#files_array').val(JSON.stringify(files_array));
});
file.previewElement.appendChild(removeButton);
});
this.on("success", function(file, responseText) {
files_array[file_inc]={};
files_array[file_inc]['file_path']=responseText['file'];
files_array[file_inc]['name']=file.name;
file_inc++;
$('#files_array').val(JSON.stringify(files_array));
});
},
});
Dropzone.options.myAwesomeDropzone = {
paramName: "file", // The name that will be used to transfer the file
maxFilesize: 15, // MB
addRemoveLinks: true,
acceptedFiles:".pdf,.jpg,.jpeg,.png,",
};
var myDropzone=新的Dropzone(“div#dropzoneDescriptionImage”{
url:“/预约/处方\u多个\u文件”,
//参数:{
//令牌:令牌,预订id:预订id,文件公司:文件公司,
// },
发送:函数(文件、xhr、formData){
append(“file_inc”,file_inc);//名称和值
append(“booking_id”,booking_id);//名称和值
formData.append(“_token”,token);
},
最大文件数:5,
init:function(){
此.on(“MaxFilesExcepended”,函数(文件){
此.removeFile(文件);
警告(“最多允许5张照片…!”;
});
this.on(“addedfile”,函数(文件){
var removeButton=Dropzone.createElement(“”);
var_this=这个;
removeButton.addEventListener(“单击”),函数(e){
e、 预防默认值();
e、 停止传播();
_此.removeFile(文件);
var i=0;
var=0;
var len=Object.keys(文件\数组).length;
对于(i=0;i这里,这段代码既有add-image,也有delete-images,它在来自后端的API调用和ajax调用上工作
var myDropzone = new Dropzone("div#dropzonePrescriptionImages", {
url: "/appointment/prescription_multiple_file",
// params: {
// _token: token,booking_id:booking_id,file_inc:file_inc,
// },
sending: function(file, xhr, formData) {
formData.append("file_inc", file_inc); //name and value
formData.append("booking_id", booking_id); //name and value
formData.append("_token",token);
},
maxFiles:5,
init: function() {
this.on("maxfilesexceeded", function(file){
this.removeFile(file);
alert("Maximum 5 photos are allowed...!");
});
this.on("addedfile", function (file) {
var removeButton = Dropzone.createElement("<button><i class='glyphicon glyphicon-trash'></i></button>");
var _this = this;
removeButton.addEventListener("click", function (e){
e.preventDefault();
e.stopPropagation();
_this.removeFile(file);
var i=0;
var found=0;
var len = Object.keys(files_array).length;
for(i=0;i<len;i++){
if(files_array.hasOwnProperty(i)){
if(files_array[i]['name'] == file.name){
$.ajax({
type: 'GET',
url:'/deletePrescriptionFiles',
dataType: 'json',
data:{path:files_array[i]['file_path']},
async:false
}).done(function(result1){
files_array[i]['file_path']=undefined;
files_array[i]['name']=undefined;
return;
});
found==1;
break;
}
if(found==1){
break;
}
}
if(found==1){
break;
}
}
$('#files_array').val(JSON.stringify(files_array));
});
file.previewElement.appendChild(removeButton);
});
this.on("success", function(file, responseText) {
files_array[file_inc]={};
files_array[file_inc]['file_path']=responseText['file'];
files_array[file_inc]['name']=file.name;
file_inc++;
$('#files_array').val(JSON.stringify(files_array));
});
},
});
Dropzone.options.myAwesomeDropzone = {
paramName: "file", // The name that will be used to transfer the file
maxFilesize: 15, // MB
addRemoveLinks: true,
acceptedFiles:".pdf,.jpg,.jpeg,.png,",
};
var myDropzone=新的Dropzone(“div#dropzoneDescriptionImage”{
url:“/预约/处方\u多个\u文件”,
//参数:{
//令牌:令牌,预订id:预订id,文件公司:文件公司,
// },
发送:函数(文件、xhr、formData){
append(“file_inc”,file_inc);//名称和值
append(“booking_id”,booking_id);//名称和值
formData.append(“_token”,token);
},
最大文件数:5,
init:function(){
此.on(“MaxFilesExcepended”,函数(文件){
此.removeFile(文件);
警告(“最多允许5张照片…!”;
});
this.on(“addedfile”,函数(文件){
var removeButton=Dropzone.createElement(“”);
var_this=这个;
removeButton.addEventListener(“单击”),函数(e){
e、 预防默认值();
e、 停止传播();
_此.removeFile(文件);
var i=0;
var=0;
var len=Object.keys(文件\数组).length;
对于(i=0;i发现问题。问题来自控制器
public function multiUpload(Request $request)
{
$imageName = time().'.'.$request->file->getClientOriginalExtension();
$request->file->move(public_path('uploads\\temp'), $imageName);
return response()->json(['success'=>$imageName]);
}
由于文件是在同一时间上载的,因此它们具有相同的名称,因此被覆盖!发现问题。问题来自控制器
public function multiUpload(Request $request)
{
$imageName = time().'.'.$request->file->getClientOriginalExtension();
$request->file->move(public_path('uploads\\temp'), $imageName);
return response()->json(['success'=>$imageName]);
}
因为文件是在同一时间上载的,所以它们采用了相同的名称,所以被覆盖了!生成随机名称,如str_random(20).time()。$request->file->getClientOriginalExtension();@Nithin是的,我这样做了。谢谢生成随机名称,如str_random(20).time()。$request->file->getClientOriginalExtension()是的,我做到了,谢谢