-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-upload.php
More file actions
88 lines (68 loc) · 2.71 KB
/
Copy pathtest-upload.php
File metadata and controls
88 lines (68 loc) · 2.71 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
<form method="post" action="" enctype="multipart/form-data">
<label>File Input: <input type="file" name="file" id="demo1" /></label>
</form>
<button class="menu-submit">添加</button>
<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="js/jquery.ajaxfileupload.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var fname = null;
var interval;
$("button.menu-submit").click(function(){
alert(fname);
// fname: the addr. of img
fname = null;
});
function applyAjaxFileUpload(element) {
$(element).AjaxFileUpload({
action: "func-upload.php",
onChange: function(filename) {
var $span = $("<span />")
.attr("class", $(this).attr("id"))
.text("Uploading")
.insertAfter($(this));
$(this).remove();
interval = window.setInterval(function() {
var text = $span.text();
if (text.length < 13) {
$span.text(text + ".");
} else {
$span.text("Uploading");
}
}, 200);
},
onSubmit: function(filename) {
return true;
},
onComplete: function(filename, response) {
fname = response['name'];
window.clearInterval(interval);
var $span = $("span." + $(this).attr("id")).text(filename + " "),
$fileInput = $("<input />")
.attr({
type: "file",
name: $(this).attr("name"),
id: $(this).attr("id")
});
if (typeof(response.error) === "string") {
$span.replaceWith($fileInput);
applyAjaxFileUpload($fileInput);
alert(response.error);
return;
}
$("<a />")
.attr("href", "#")
.text("x")
.bind("click", function(e) {
$span.replaceWith($fileInput);
applyAjaxFileUpload($fileInput);
})
.appendTo($span);
}
});
}
applyAjaxFileUpload("#demo1");
});
</script>
</body>
</html>