forked from jimi79/share
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.php
More file actions
96 lines (81 loc) · 2.44 KB
/
gui.php
File metadata and controls
96 lines (81 loc) · 2.44 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<html>
<head>
<script>
function uploadFile(file) {
var xhr = new XMLHttpRequest();
xhr.upload.onprogress = function(e) {
var percentComplete = (e.loaded / e.total) * 100;
document.getElementById("pasteOutput").innerHTML = "Uploaded " + percentComplete + "%";
};
var fd = new FormData();
fd.append("data", file);
// These extra params aren't necessary but show that you can include other data.
if (pastePassword.value != '') {
fd.append("password", pastePassword.value);
}
if (pastePassword.duration != '') {
fd.append("duration", pasteDuration.value);
}
xhr.onload = function() {
if (xhr.status == 200) {
document.getElementById("pasteOutput").innerHTML = xhr.responseText;
} else {
alert("Error! Upload failed");
document.getElementById("pasteOutput").innerHTML = 'Upload failed';
}
};
xhr.onerror = function() {
alert("Error! Upload failed. Can not connect to server.");
};
xhr.open("POST", "gui_upload.php", true);
//xhr.setRequestHeader("Content-Type", file.type);
console.log(file);
//xhr.send(file);
xhr.send(fd);
}
function handlePaste(e) {
for (var i = 0 ; i < e.clipboardData.items.length ; i++) {
var item = e.clipboardData.items[i];
if (item.type.indexOf("image") -1) {
uploadFile(item.getAsFile());
} else {
console.log("Discardingimage paste data");
}
}
}
</script>
</head>
<body>
<fieldset>
<legend>Usual upload button (you can drag n' drop)</legend>
<div>
<form class="box" method="post" action="share.php" enctype="multipart/form-data">
Duration in minutes (link will work only in that duration):<input type="numeric" min="1" />
<br>Password:<input type="password" name="password" />
<input type="file" name="data" />
<br/>
<button type="submit">Upload</button>
</form>
</div>
</fieldset>
<fieldset>
<legend>Copy paste</legend>
Start with filling the password etc before, as soon as you paste the link is created
<br>Duration in minutes (link will work only in that duration):<input id="pasteDuration" type="numeric" min="1" />
<br>Password:<input type="password" id="pastePassword" name="password" />
<div id="pasteTarget">
<fieldset style="width: 200px; height:100px">
<legend>click and past here</legend>
</fieldset>
</div>
<div id="pasteOutput">
Link will appear here
</div>
</fieldset>
</body>
<script>
window.onload = function() {
document.getElementById("pasteTarget").addEventListener("paste", handlePaste);
}
</script>
</html>