-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
71 lines (54 loc) · 1.24 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<html>
<head>
<title>Upload files</title>
<link rel="stylesheet" type="text/css" href="css/body.css">
</head>
<body>
<div id="uploads"></div>
<div class="dropzone" id="dropzone">Drop files to upload</div>
<script type="text/javascript">
(function(){
var dropzone = document.getElementById('dropzone');
var displayUploads = function(data){
var uploads = document.getElementById('uploads'),
anchor,
x;
for (x=0;x<data.length;x=x+1) {
anchor = document.createElement('a');
anchor.href = data[x].file;
anchor.innerText=data[x].name;
uploads.appendChild(anchor);
}
}
var upload = function(files){
var formData = new FormData(),
xhr = new XMLHttpRequest(),
x;
for(x=0;x<files.length;x=x+1){
formData.append('file[]',files[x]);
}
xhr.open('post','upload.php');
xhr.send(formData);
xhr.onload = function(){
console.log(this.responseText);
var data = JSON.parse(this.responseText);
displayUploads(data);
}
}
dropzone.ondrop = function(e){
e.preventDefault();
this.className='dropzone';
upload(e.dataTransfer.files);
};
dropzone.ondragover = function(){
this.className = 'dropzone dragover';
return false;
};
dropzone.ondragleave = function(){
this.className = 'dropzone';
return false;
};
}());
</script>
</body>
</html>