Dropzone.js - Display existing files on server

前端 未结 5 1884
我寻月下人不归
我寻月下人不归 2020-12-15 10:04

I\'m currently using dropzone.js v3.10.2 I am having issues displaying my existing files I have already uploaded. I am more than competent with php however I have limited kn

5条回答
  •  情话喂你
    2020-12-15 10:49

    I checked the code (from starTutorial) and it didn't work for me either(?)

    I managed to get it working by replacing this:

    $.get('upload.php', function(data) {
      $.each(data, function(key,value) {
        var mockFile = { name: value.name, size: value.size };
        thisDropzone.options.addedfile.call(thisDropzone, mockFile);
        thisDropzone.options.thumbnail.call(thisDropzone, mockFile, "uploads/"+value.name);
      });
    });
    

    with this:

    $.getJSON('files/list-all', function(data) {
      $.each(data, function(index, val) {
        var mockFile = { name: val.name, size: val.size };
        thisDropzone.options.addedfile.call(thisDropzone, mockFile);
        thisDropzone.options.thumbnail.call(thisDropzone, mockFile, "uploads/" + val.name);
      });
    });
    

    Credit to this answer: https://stackoverflow.com/a/5531883/984975

    EDIT: In version 4.0 the thumbnails of the existing files will be showed with the cue bar in it. To solve this add:

    thisDropzone.emit("complete", mockFile);
    

提交回复
热议问题