multimodalart HF Staff commited on
Commit
e7f5f1e
·
1 Parent(s): 6f058fb

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +49 -14
index.html CHANGED
@@ -1,23 +1,58 @@
1
  <!DOCTYPE html>
2
  <html>
 
 
 
 
 
 
 
 
 
 
 
 
3
  <body>
 
 
 
 
 
4
 
5
- <h1>Folder Upload Demo</h1>
 
 
 
6
 
7
- <p>Drag and drop a folder, or click to select a folder:</p>
 
 
8
 
9
- <input type="file" id="folderUpload" webkitdirectory directory multiple />
10
-
11
- <script>
12
- document.getElementById('folderUpload').addEventListener('change', function(e) {
13
- const files = e.target.files; // FileList object
14
-
15
- // loop through the FileList and print details
16
- for (let i = 0, f; f = files[i]; i++) {
17
- console.log('File:', f.webkitRelativePath);
18
- }
19
- });
20
- </script>
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  </body>
23
  </html>
 
1
  <!DOCTYPE html>
2
  <html>
3
+ <head>
4
+ <title>Drag and Drop Demo</title>
5
+ <style>
6
+ #drop_zone {
7
+ width: 300px;
8
+ height: 200px;
9
+ border: 2px dashed #aaa;
10
+ line-height: 200px;
11
+ text-align: center;
12
+ }
13
+ </style>
14
+ </head>
15
  <body>
16
+ <div id="drop_zone">Drop files or folders here</div>
17
+ <input type="file" id="fileInput" webkitdirectory="" multiple />
18
+ <script>
19
+ let dropZone = document.getElementById('drop_zone');
20
+ let fileInput = document.getElementById('fileInput');
21
 
22
+ dropZone.ondragover = function (event) {
23
+ event.preventDefault();
24
+ this.style.backgroundColor = '#ccc';
25
+ };
26
 
27
+ dropZone.ondrop = function (event) {
28
+ event.preventDefault();
29
+ this.style.backgroundColor = '#fff';
30
 
31
+ let items = event.dataTransfer.items;
32
+ for (let i = 0; i < items.length; i++) {
33
+ let item = items[i].webkitGetAsEntry();
34
+ if (item) {
35
+ traverseFileTree(item);
36
+ }
37
+ }
38
+ };
 
 
 
 
39
 
40
+ function traverseFileTree(item, path = '') {
41
+ if (item.isFile) {
42
+ // Get file
43
+ item.file(function(file) {
44
+ console.log("File:", path + file.name);
45
+ });
46
+ } else if (item.isDirectory) {
47
+ // Get folder contents
48
+ let dirReader = item.createReader();
49
+ dirReader.readEntries(function(entries) {
50
+ for (let i=0; i<entries.length; i++) {
51
+ traverseFileTree(entries[i], path + item.name + "/");
52
+ }
53
+ });
54
+ }
55
+ }
56
+ </script>
57
  </body>
58
  </html>