Advertisement
Guest User

Dropzonejs keep directory structure

a guest
Dec 4th, 2018
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <head>
  3. <meta charset="UTF-8">
  4. <title>Folder uploader, keeping recursive directory structure</title>
  5. <link href="css/dropzone.css" type="text/css" rel="stylesheet" />
  6. </head>
  7. <body>
  8. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  9. <script>window.jQuery || document.write('<script src="assets/js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
  10.  
  11. <script src="https://cdnjs.cloudflare.com/ajax/libs/blueimp-md5/2.10.0/js/md5.min.js"></script>
  12.  
  13. <script src="js/dropzone.js"></script>
  14.  
  15. <form action="upload.php" class="dropzone" id="uploadFile" name="uploadFile" method="POST">
  16. <span id="tmp-path"></span>
  17. </form>
  18.  
  19. <script>
  20. $(document).ready(function () {
  21. Dropzone.autoDiscover = false;
  22. $("#uploadFile").attr("class","dropzone");
  23. // calculating the dropzone singleton
  24. var dropzoneSingelton = md5(new Date());
  25. Dropzone.options.uploadFile = {
  26. init: function() {
  27. this.on("success", function(file, responseText) {
  28. file.previewTemplate.appendChild(document.createTextNode(responseText));
  29. });
  30.  
  31. this.on("sending", function(file) {
  32. if(typeof file.fullPath != "undefined"){
  33. // this solution will upload all dropped folders files in a single directory
  34. var changePath = file.fullPath.split("/");
  35. changePath[0] = dropzoneSingelton;
  36. changePath = changePath.join("/");
  37.  
  38. // this path will keep the name of the dropped folders in the server directory to differentiate the files and keep local structure
  39. // var changePath = dropzoneSingelton + "/" + file.fullPath;
  40.  
  41. $("form").append('<input type="hidden" name="path" value="'+changePath+'" />')
  42. var el1 = document.getElementById('insertHere1')
  43. el1.innerHTML = changePath
  44. var el2 = document.getElementById('insertHere2')
  45. el2.innerHTML = '<a href="http://example1.com/'+ dropzoneSingelton +'" target="_blank">Open HTTP URL in a new window</a>*'
  46. var el3 = document.getElementById('insertHere3')
  47. el3.innerHTML = '<a href="http://example2.com/'+ dropzoneSingelton +'" target="_blank">Open HTTP/2 URL in a new window</a>*'
  48. var el4 = document.getElementById('insertHere4')
  49. el4.innerHTML = '<b>*</b>Temporary URLs will no longer be availabe to copy once you leave this page. URLs and files will be delete from the server in 30 minutes.'
  50.  
  51. }
  52. });
  53. }
  54. };
  55.  
  56. var myDropzone = new Dropzone("#uploadFile", {
  57. url: "upload.php"
  58. });
  59.  
  60. });
  61. </script>
  62.  
  63.  
  64. <div class="test-urls">
  65. <div id="insertHere1"></div>
  66. <div id="insertHere2"></div>
  67. <div id="insertHere3"></div>
  68. <div id="insertHere4"></div>
  69. </div>
  70.  
  71. </body>
  72. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement