-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
109 lines (96 loc) · 5.16 KB
/
index.html
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
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html>
<head>
<!--# version: 1.2.0 -->
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<!-- fallback -->
<!-- <script src="redist/jquery.min.js"></script> -->
<!-- dropzone 6 drops support for IE; also cdnjs.cloudflare is 50% faster then unpkg -->
<!-- <link rel="stylesheet" href="https://unpkg.com/dropzone@5/dist/min/dropzone.min.css" type="text/css" /> -->
<!-- <script src="https://unpkg.com/dropzone@5/dist/min/dropzone.min.js"></script> -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.3/dropzone.min.css" rel="stylesheet" type="text/css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.3/min/dropzone.min.js" type="text/javascript"></script>
<!-- fallback -->
<!-- <link href="redist/dropzone.min.css" rel="stylesheet" type="text/css"> -->
<!-- <script src="redist/dropzone.min.js" type="text/javascript"></script> -->
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body >
<div>
<div>Command line: curl <span id="url"></span>upload-basic.php -F userfile=@<i>file.ext</i></div>
<form enctype="multipart/form-data" action="upload-basic.php" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="100999999" />
<!-- Name of input element determines name in $_FILES array -->
Fallback no chunck: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
<script type="text/javascript">document.getElementById("url").innerHTML = window.location.href;</script>
</div>
<div class="container" >
<div class='content'>
<script>
// https://github.com/dropzone/dropzone/blob/main/src/options.js
// https://stackoverflow.com/questions/56156402/how-to-concatenate-chunked-file-uploads-from-dropzone-js-with-php
// https://stackoverflow.com/questions/49769853/dropzone-js-chunking
// $(function () { // this gives an error: Uncaught Error: Dropzone already attached.
// myDropzone = new Dropzone('#dropzone', {
Dropzone.options.dropzone = {
accept: function(file, done) {
// console.debug(Dropzone);
if (file.name == "forbidden-filename.vbs") {
done("Naha, you don't.");
} else { done(); }
},
/*
init: function() {
this.on("uploadprogress", function(file, progress) {
console.log("File progress", progress);
});
},
*/
maxFilesize: 2048, // Mbytes
chunking: true,
chunkSize: 1000000, // bytes
parallelChunkUploads: true,
retryChunks: true,
forceChunking: true,
chunksUploaded: function(file, done) {
// All chunks have been uploaded. Perform any other actions
let currentFile = file;
// TODO: html protect fileName
let fileName = currentFile.name.split('.').slice(0, -1).join('.') || currentFile.name;
let fileExt = currentFile.name.slice((currentFile.name.lastIndexOf(".") - 1 >>> 0) + 2);
//console.debug("currentFile:", currentFile);
// Remove anything which isn't a word, whitespace, number, or any of the following caracters: "-_~[]()."
<!-- fileName.replace(/([^\w\s\d\-_~\[\]\(\)\.]+)/gi, '').replace(/([\.]{2,})/g, '.'); -->
fileName.replace(/([^\w \d\-_~\[\]\(\)\.]+)/gi, '').replace(/([\.]{2,})/g, '.');
// This calls server-side code to merge all chunks for the currentFile
//console.debug("url:","chunk-concat.php?dzuuid=" + currentFile.upload.uuid + "&dztotalchunkcount=" + currentFile.upload.totalChunkCount + "&fileName=" + fileName + "&fileExt=" + fileExt);
$.ajax({
url: "chunk-concat.php?dzuuid=" + currentFile.upload.uuid + "&dztotalchunkcount=" + currentFile.upload.totalChunkCount + "&fileName=" + fileName + "&fileExt=" + fileExt,
success: function (data) {
done();
},
error: function (msg) {
console.error(msg);
currentFile.accepted = false;
myDropzone._errorProcessing([currentFile], msg.responseText);
}
});
}
} // Dropzone.options.dropzone
// }); // var myDropzone = new Dropzone
// }); // $(function ()
</script>
<!-- <form id="dropzone" action="test/upload.php" class="dropzone" method="post" enctype="multipart/form-data"> -->
<form id="dropzone" action="chunk-upload.php" class="dropzone" method="post" enctype="multipart/form-data">
<div class="fallback">
<input name="file" type="file" multiple />
</div>
</form>
</div>
</div>
</body>
</html>