Witam.
Mam taki kod:

  1.  
  2. Dropzone.options.dpzMultipleFiles = {
  3. uploadMultiple: true,
  4. paramName: "file",
  5. maxFilesize: 100,
  6. maxFiles: 2,
  7. createImageThumbnails: true,
  8. acceptedFiles: ".png,.jpg,.jpeg",
  9. clickable: true,
  10. thumbnailWidth: 200,
  11. thumbnailHeight: 200,
  12. autoProcessQueue: false,
  13. init: function () {
  14. var submitButton = document.querySelector("#submit-all")
  15. dpzMultipleFiles = this;
  16. submitButton.addEventListener("click", function () {
  17. dpzMultipleFiles.processQueue();
  18. });
  19.  
  20.  
  21.  
  22. $.ajax({
  23. url: 'http://localhost/admin/dropZoneUpload.php?parm=1',
  24. type: 'get',
  25. dataType: 'json',
  26. cache: false,
  27. success: function (response) {
  28. $.each(response, function (key, value) {
  29. var mockFile = {name: value.name, size: value.size}
  30.  
  31. dpzMultipleFiles.emit('addedfile', mockFile)
  32. dpzMultipleFiles.emit('thumbnail', mockFile, value.path)
  33. dpzMultipleFiles.emit('complete', mockFile)
  34. })
  35. }
  36. });
  37.  
  38.  
  39.  
  40.  
  41. this.on('completemultiple', function (file, json) {
  42. //$('.sortable').sortable('enable');
  43. });
  44. // this.on("thumbnail", function(file, dataUrl) {
  45. // $('.dz-image').last().find('img').attr({width: '100%', height: '100%'});
  46. // }),
  47. this.on('success', function (file, json) {
  48. if (file.accepted == true) {
  49.  
  50. $('.dz-preview').remove();
  51.  
  52. $.ajax({
  53. url: 'http://localhost/psCMS2/admin/dropZoneUpload.php?parm=1',
  54. type: 'get',
  55. dataType: 'json',
  56. cache: false,
  57. success: function (response) {
  58. console.log(response);
  59. $.each(response, function (key, value) {
  60. var mockFile = {name: value.name, size: value.size}
  61. dpzMultipleFiles.emit('addedfile', mockFile)
  62. dpzMultipleFiles.emit('thumbnail', mockFile, value.path)
  63. dpzMultipleFiles.emit('complete', mockFile)
  64. });
  65. }
  66. });
  67.  
  68.  
  69.  
  70. }
  71. /////////
  72. });
  73.  
  74. this.on("addedfile", function (file) {
  75. var removeButton = Dropzone.createElement("<button> Remove file </button>");
  76. var _this = this;
  77.  
  78. removeButton.addEventListener("click", function (e) {
  79. // Make sure the button click doesn't submit the form:
  80. e.preventDefault();
  81. e.stopPropagation();
  82.  
  83. $.ajax({
  84. url: 'http://localhost/psCMS2/admin/dropZoneUpload.php?removeFile=' + file.name,
  85. dataType: 'text',
  86. type: 'post',
  87. cache: false,
  88. data: $(this).serialize(),
  89. success: function (data, textStatus, jQxhr) {
  90. x = confirm('Do you want to delete this logo?');
  91. if(!x) return false;
  92. //_this.removeFile();
  93. dpzMultipleFiles.options.maxFiles = dpzMultipleFiles.options.maxFiles + 1;
  94. console.log("kasuje " + file.name);
  95. alert('http://localhost/psCMS2/admin/dropZoneUpload.php?removeFile=' + file.name);
  96. }, error: function (jqXhr, textStatus, errorThrown) {
  97. console.log(errorThrown);
  98. }
  99. });
  100. });
  101. file.previewElement.appendChild(removeButton);
  102. });
  103. this.on("maxfilesexceeded", function (file) {
  104. this.removeFile(file);
  105. });
  106. this.on('resetFiles', function() {
  107. dpzMultipleFiles.removeAllFiles();
  108. });
  109. this.on('queuecomplete', function(){
  110. //$('.dz-preview').remove();
  111. });
  112. this.on('drop', function(){
  113.  
  114. });
  115. this.on('complete', function(){
  116. this.removeFile(file);
  117. });
  118. }
  119. };
  120.  


Pliki wgrywają się poprawnie.
Mam problem z wyczyszczeniem wszystkich elementów w dropzone. Chciałbym żeby przed każdym wyświetleniem aktualnych plików najpierw wyczyścił stare.

W tej chwili po dodaniu obrazka - obrazek wysyła się na serwer, ale na liście widzę stare pliki. Muszę przeładować przeglądarkę żeby zobaczyć nowe.

Wie ktoś może jak to naprawić?



Dodałem pełen kod: https://bitbucket.org/trifek/dropzone/src/master/