Uploading multiple files with the same file.name using dropzone.js

前端 未结 4 552
Happy的楠姐
Happy的楠姐 2020-12-18 17:13

I\'m implementing dropzone.js and everything is perfect until I try to upload multiple files with the same name, let\'s say uploading photos from an iOS device where all hav

4条回答
  •  温柔的废话
    2020-12-18 17:49

    The solution of @Hien works, but, the problem is when you upload 2 or more files with the same original name, because your for loop will match always the first image on the array, and will remove this element. but, this element is not necessarily the image that you want to remove...

    I have added the "file.lastModified" property to your dropzone_files[], cause it seems to be unique. It works for me:

    dropzone_files.push({'new_name': response, 'old_name': file.name, 'lastModified':file.lastModified});
    

    And then, in your if condition:

    if (file.name == dropzone_files[i]['old_name'] && file.lastModified==dropzone_files[i]['lastModified']) {/**/}
    

    Note: I think lastmodify is unique, so, maybe another solution is: store lastmodify value with your img on your Database. Then, you could store this unique value in your removeData. Then, in your php, call the query "DELETE FROM images WHERE lastmodify=removeData";

    For example...

    Hope this help.

提交回复
热议问题