-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupload.php
85 lines (77 loc) · 2.17 KB
/
upload.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
session_start();
session_unset();
include 'layout.php';
$layout = new Layout();
$layout->header();
$layout->nav('upload.php');
?>
<div class="container">
<script src="js/bootstrap.file-input.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('input[type=file]').bootstrapFileInput();
var files;
$('input[type=file]').on('change', function prepareUpload(event) {
files = event.target.files;
});
$('#submit').on('click', function(e){
e.stopPropagation();
e.preventDefault();
var form = $(this);
var data = new FormData();
data.append('lh', files[0]);
$('#myform').hide();
$('#progress-container').show('slow');
var monitor = function() {
$.ajax({
url : 'monitor.php',
success : function (data) {
console.log(data);
$('#progress').attr('aria-valuenow', data).css('width', data+'%');
}
});
};
var timer = setInterval(monitor, 1000);
var formAction = form.attr('action');
$.ajax({
url : 'process.php',
data : data,
cache : false,
contentType : false,
processData : false,
type : 'POST',
success : function(data, textStatus, jqXHR){
console.log(data);
$('#debug').append(data);
clearInterval(timer);
monitor();
},
error : function(data) {
console.log(data);
$('#debug').append(data);
clearInterval(timer);
}
});
});
});
</script>
<form action="process.php" method="POST" enctype="multipart/form-data" class="form-inline" role="form" id='myform'>
<fieldset>
<legend>File Upload</legend>
<div class="form-group">
<input type="file" name="lh" class="btn btn-default" title="Choose file">
<input type="button" value="Let's go!" class="btn btn-primary" id='submit'>
</div>
</fieldset>
</form>
<div id='progress-container' style='display:none'>
<div class="progress progress-striped active">
<div id='progress' class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%"></div>
</div>
</div>
<div id='debug'></div>
</div>
<?php
$layout->footer();
?>