Spaces:
Running
Running
Commit
·
e7f5f1e
1
Parent(s):
6f058fb
Update index.html
Browse files- index.html +49 -14
index.html
CHANGED
@@ -1,23 +1,58 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
<body>
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
|
|
|
|
|
|
|
6 |
|
7 |
-
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
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>
|