欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

jquery+php+ajax显示上传进度的多图片上传并生成缩略图代码_php技巧

程序员文章站 2022-06-15 15:14:24
...
本例用到其他2个php class.upload.php和 functions.php还有css和js以及img文件

完整实例代码点击此处本站下载

效果图如下:

jquery+php+ajax显示上传进度的多图片上传并生成缩略图代码_php技巧

实现代码如下:

JavaScript代码如下:

复制代码 代码如下:

javascript代码如下:

复制代码 代码如下:
',
css: {
border: 'none',
backgroundColor: 'none'
},
overlayCSS: {
backgroundColor: '#fff',
opacity: '0',
cursor: 'wait'
}
});
});

var uploader = new plupload.Uploader({
runtimes : 'flash, html5',
browse_button : 'pickfiles',
container : 'uploader',
max_file_size : '10mb',
url : 'upload.php',
flash_swf_url : 'uploader/uploader.swf',
filters : [
{ title : "Image files", extensions : "jpg,jpeg,gif,png" }
]
});

uploader.bind('Init', function(up, params) {});
uploader.init();

uploader.bind('FilesAdded', function(up, files) {
/*
@@ Show / hide various elements
*/
$('.upload-message').hide();
$('.info-message').hide();
$('#upload_button').show();
$('#filelist_header').show();

$.each(files, function(i, file) {
$('#filelist').append(
'
' +
'
'+file.name + '
'+
'
' + plupload.formatSize(file.size) + '
'+
'
0%
'+
'
jquery+php+ajax显示上传进度的多图片上传并生成缩略图代码_php技巧
' +
'
');

$('#remove_'+file.id).click(function(e) {
uploader.removeFile(file)
$('#'+file.id).hide('slow', function() { ('#'+file.id).remove(); });
});
});

up.refresh();
$('#filelist').animate({scrollTop: $('#filelist').attr("scrollHeight")}, 1500);
});

uploader.bind('UploadProgress', function(up, file) {
$('#status_' + file.id).html(file.percent + "%");
if(file.percent == 100) {
$('#' + file.id).block({
message: '',
css: {
border: 'none',
backgroundColor: 'none'
},
overlayCSS: {
backgroundColor: '#fff',
opacity: '0.7',
cursor: 'wait'
}
});
}
$('#percent').width(uploader.total.percent+"%");
$('#upRate').text(Math.ceil(uploader.total.bytesPerSec/1024)+" kb/sec");
});

uploader.bind('FileUploaded', function(up, file, response) {
var input = $("#uploaded_photos");
var data = response.response;
var details = data.split(',');
if(details[0] == 'success') {
var photo_html = '
jquery+php+ajax显示上传进度的多图片上传并生成缩略图代码_php技巧

'+details[1]+'

';
input.val(input.val() + details[1] + ":");
} else {
var photo_html = '
'+details[1]+'
';
}
$('.side-pane').prepend(photo_html);
$('.time').timeago();
});

uploader.bind('UploadComplete', function(up, files) {
$('#upload_info').hide();
$('#filelist').unblock({
onUnblock: function () {
$('#filelist_header').hide();
$('#filelist').html('
ok
All photos have been uploaded.
');
}
});
});

// ]]>