-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
75 lines (47 loc) · 1.31 KB
/
script.js
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
72
73
74
75
// Arrastar
$('.upload-content').on('dragenter', function (e) {
e.stopPropagation();
e.preventDefault();
$(".upload-content-title").text("Solte aqui");
});
// Arrastar :hover
$('.upload-content').on('dragover', function (e) {
e.stopPropagation();
e.preventDefault();
$(".upload-content-title").text("Solte aqui");
});
// Soltar
$('.upload-content').on('drop', function (e) {
e.stopPropagation();
e.preventDefault();
$(".upload-content-title").text("Carregando...");
var fd = new FormData();
var file = e.originalEvent.dataTransfer.files;
fd.append('file', file[0]);
upload(fd);
});
// Abrir arquivo seletor quando clicar na div
$("#uploadfile").on('click', function () {
$("#file").click();
});
// Arquivo selecionado
$("#file").change(function () {
var fd = new FormData();
var files = $('#file')[0].files[0];
fd.append('file', files);
upload(fd);
});
function upload(formData) {
$.ajax({
url: "upload.php",
type: "POST",
data: formData,
contentType: false,
processData: false,
dataType: 'json',
success: response => {
console.log(response);
$(".upload-content-title").text("Solte o arquivo aqui ou clique para selecionar o mesmo");
}
});
}