Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <head>
- <meta charset="UTF-8">
- <title>Folder uploader, keeping recursive directory structure</title>
- <link href="css/dropzone.css" type="text/css" rel="stylesheet" />
- </head>
- <body>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
- <script>window.jQuery || document.write('<script src="assets/js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/blueimp-md5/2.10.0/js/md5.min.js"></script>
- <script src="js/dropzone.js"></script>
- <form action="upload.php" class="dropzone" id="uploadFile" name="uploadFile" method="POST">
- <span id="tmp-path"></span>
- </form>
- <script>
- $(document).ready(function () {
- Dropzone.autoDiscover = false;
- $("#uploadFile").attr("class","dropzone");
- // calculating the dropzone singleton
- var dropzoneSingelton = md5(new Date());
- Dropzone.options.uploadFile = {
- init: function() {
- this.on("success", function(file, responseText) {
- file.previewTemplate.appendChild(document.createTextNode(responseText));
- });
- this.on("sending", function(file) {
- if(typeof file.fullPath != "undefined"){
- // this solution will upload all dropped folders files in a single directory
- var changePath = file.fullPath.split("/");
- changePath[0] = dropzoneSingelton;
- changePath = changePath.join("/");
- // this path will keep the name of the dropped folders in the server directory to differentiate the files and keep local structure
- // var changePath = dropzoneSingelton + "/" + file.fullPath;
- $("form").append('<input type="hidden" name="path" value="'+changePath+'" />')
- var el1 = document.getElementById('insertHere1')
- el1.innerHTML = changePath
- var el2 = document.getElementById('insertHere2')
- el2.innerHTML = '<a href="http://example1.com/'+ dropzoneSingelton +'" target="_blank">Open HTTP URL in a new window</a>*'
- var el3 = document.getElementById('insertHere3')
- el3.innerHTML = '<a href="http://example2.com/'+ dropzoneSingelton +'" target="_blank">Open HTTP/2 URL in a new window</a>*'
- var el4 = document.getElementById('insertHere4')
- 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.'
- }
- });
- }
- };
- var myDropzone = new Dropzone("#uploadFile", {
- url: "upload.php"
- });
- });
- </script>
- <div class="test-urls">
- <div id="insertHere1"></div>
- <div id="insertHere2"></div>
- <div id="insertHere3"></div>
- <div id="insertHere4"></div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement