<html>
<head>
<script src="./jquery-1.2.6.js" type="text/javascript"></script>
<script src="./jquery.ajax_upload.0.9.min.js"" type="text/javascript"></script>
<script>
/*<![CDATA[*/
$(document).ready(function(){
new Ajax_upload('#example1_button', {
action: 'upload.php', //-处理页面
name: 'myfile', //-文件名
onSubmit: function(file, ext)
{
var allowed = ['avi', 'jpg', 'png', 'gif', 'jpeg']; //----允许格式(数组)
if ($.inArray(String(ext), allowed) === -1)
{
$('#example1_message').text('Error: only images are allowed');
return false;
}
$('#example1_message').text('Uploading……');
this.disable();
},
onComplete: function(file, response)
{
$('#example1_message').text(file + ' uploaded');
this.enable();
$('<li></li>').appendTo('#example1_files').text(file);
},
onerror: function(file, response)
{
$('#example1_message').text(response);
}
});
});
/*]]>*/
</script>
</head>
<body>
<div id="example1">
<p>You can allow only certain file types</p>
<div id="example1_wrapper">
<div id="example1_button">Upload</div>
</div>
<p id="example1_message"></p>
<UL id="example1_files"></UL>
</div>
</body>
</html>