Menu

[r697]: / branches / code-cleanup / simple-test.html  Maximize  Restore  History

Download this file

155 lines (148 with data), 6.5 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
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>SWFUpload v2.0 simplified with jQuery interface and a nice fallback</title>
<style rel="stylesheet">
body {
margin:0;
padding:1em;
}
fieldset {
padding:1em;
margin:0;
}
</style>
<script type="text/javascript" src="swfupload/swfupload.js"></script>
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<form action="/images/" method="post" enctype="multipart/form-data" target="target-iframe" id="upload-form">
<fieldset>
<legend>Files uploaded</legend>
<!-- the upload target is used as an anchor on submit in some browsers -->
<iframe id="target-iframe" name="target-iframe" style="height:1.3em;width:100%;"></iframe>
<ul id="progress-target">
</ul>
<p id="multiple-upload" style="display:none">
<input type="button" value="Upload files (Max 3 MB)" id="upload-button" />
<input id="cancel-button" type="button" value="Cancel uploads" disabled="disabled" />
</p>
<p id="single-upload">
<!-- it's better not to change the name of the field -->
<input type="file" name="FileData" id="file" /> (Max 3 MB)
<input type="submit" value="Upload file" id="submit-button" />
<br />
</p>
</fieldset>
</form>
<script type="text/javascript">
// avoid polluting the namespace
(function(){
// hide the iframe : a browser without javascript still has a feedback
$('#target-iframe').css('height', 0).css('width', 0).css('border', 0);
// callbacks for the SWF movie
var handlers = {
uploadReady: function(){
$('#multiple-upload').show();
$('#single-upload').hide();
},
fileDialogComplete: function(num_files_queued) {
if (this.getStats().files_queued > 0) {
$('#cancel-button').attr('disabled', 'disabled');
}
this.startUpload();
},
uploadStart: function(fileObj) {
$('#cancel-button').attr('disabled', false);
$('#upload-button').attr('disabled', 'disabled');
$('#progress-target').append($('<li id="'+fileObj.id+'">'+fileObj.name+' <span></span></li>'));
return true;
},
uploadProgress: function(fileObj, bytesLoaded, bytesTotal) {
var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
$('#'+fileObj.id+' span').html(' : '+percent+'%');
},
uploadSuccess: function(fileObj, server_data) {
$('#'+fileObj.id+' span').html(' : Done');
},
uploadComplete: function(fileObj) {
if (this.getStats().files_queued == 0) {
$('#cancel-button').attr('disabled', 'disabled');
$('#upload-button').attr('disabled', false);
} else {
this.startUpload();
}
},
uploadError: function(file, error_code, message) {
$('#'+file.id).text("Error during upload : "+ this.uploadErrorMessage(error_code));
}
};
// SWFUpload instance
var upload = new SWFUpload({
// Backend Settings
post_params: {"PHPSESSID" : "32f32f3"},
upload_url: $('#upload-form')[0].action,
// File Upload Settings
file_size_limit : "3072", // 3MB
file_types : "*.*",
file_types_description : "All Files",
file_upload_limit : "10",
file_queue_limit : "0",
// Event Handler Settings
fileDialogComplete : handlers.fileDialogComplete,
uploadStart : handlers.uploadStart,
uploadProgress : handlers.uploadProgress,
uploadSuccess : handlers.uploadSuccess,
uploadComplete : handlers.uploadComplete,
uploadReady : handlers.uploadReady,
uploadError : handlers.uploadError,
flash_url : "swfupload/swfupload_f8.swf",
debug_enabled: true
});
$('#upload-button').click(function() {
upload.selectFiles();
$('#cancel-button').attr('disabled', false);
});
$('#cancel-button').click(function() {
upload.cancelQueue();
$('#cancel-button').attr('disabled', 'disabled');
});
// handle response for single upload
var handle_response = function(iframe) {
if(!iframe.contentWindow)
return
response = iframe.contentWindow.document.getElementsByTagName('body')[0].innerHTML;
if(!response || $.trim(response) == "") {
return;
}
// the server response has to be like this : sucess;message
response = response.split(";");
if(response[0] == 'success')
$('#progress-target').append($('<li>'+response[1]+' <span>: Done.</span></li>'));
else
$('#progress-target').append($('<li class="failed">Upload as failed : '+ response[1] +'</li>'));
$('#file').before($('<input type="file" name="FileData" id="file" />')).remove();
$('#submit-button').attr('disabled', false);
}
$('#target-iframe')[0].onload = function() {
handle_response(this);
}
$('#upload-form').submit(function() {
$('#submit-button').attr('disabled','disabled');
// ie don't understand onload on iframe correctly
if($.browser.msie) {
alert("ie")
var inter = setInterval(function() {
if($('#target-iframe')[0].contentWindow.document){
clearInterval(inter);
handle_response($('#target-iframe')[0]);
}
}, 500);
}
return true;
}
);
}());
</script>
</body>
</html>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.