我正在使用plupload。我想在第一个上传链接上传图像,然后在第二个链接上传文档。我在wordpress模板文件中这样做。那么如何使用plupload实现这一点? 这是我的js代码...
jQuery(document).ready(function($) {
"use strict";
if (typeof(plupload) !== 'undefined') {
var uploader = new plupload.Uploader(ajax_vars.plupload);
uploader.init();
uploader.bind('FilesAdded', function (up, files) {
$.each(files, function (i, file) {
// console.log('append'+file.id );
$('#aaiu-upload-imagelist').append(
'<div id="' + file.id + '">' +
file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' +
'</div>');
});
up.refresh(); // Reposition Flash/Silverlight
uploader.start();
});
uploader.bind('UploadProgress', function (up, file) {
$('#' + file.id + " b").html(file.percent + "%");
});
// On erro occur
uploader.bind('Error', function (up, err) {
$('#aaiu-upload-imagelist').append("<div>Error: " + err.code +
", Message: " + err.message +
(err.file ? ", File: " + err.file.name : "") +
"</div>"
);
up.refresh(); // Reposition Flash/Silverlight
});
uploader.bind('FileUploaded', function (up, file, response) {
var result = $.parseJSON(response.response);
// console.log(result);
$('#' + file.id).remove();
if (result.success) {
$('#profile-image').css('background-image','url("'+result.html+'")');
$('#profile-image').attr('data-profileurl',result.html);
$('#profile-image_id').val(result.attach);
var all_id=$('#attachid').val();
all_id=all_id+","+result.attach;
$('#attachid').val(all_id);
$('#imagelist').append('<div class="uploaded_images" data-
imageid="'+result.attach+'"><img src="'+result.html+'" alt="thumb" /><i class="fa
deleter fa-trash-o"></i> </div>');
delete_binder();
thumb_setter();
}
});
$('#aaiu-uploader').click(function (e) {
uploader.start();
e.preventDefault();
});
$('#aaiu-uploader2').click(function (e) {
uploader.start();
e.preventDefault();
});
}
});
这是我的第一个上传链接的模板文件代码,它完美运行...
<div id="upload-container">
<div id="aaiu-upload-container">
<div id="aaiu-upload-imagelist">
<ul id="aaiu-ul-list" class="aaiu-upload-list"></ul>
</div>
<div id="imagelist">
<?php
if($images!=''){
print $images;
}
?>
</div>
<a id="aaiu-uploader" class="aaiu_button" href="#"><?php
_e('*Select Images (mandatory)','wpestate');?></a>
<input type="hidden" name="attachid" id="attachid" value="<?php
echo $attachid;?>">
<input type="hidden" name="attachthumb" id="attachthumb"
value="<?php echo $thumbid;?>">
</div>
<span class="upload_explain"><?php _e('*click to set the featured
image','wpestate');?></span>
</div>
</div>
这是第二个上传链接的代码......
<div id="upload-container">
<div id="aaiu-upload-container">
<div id="aaiu-upload-imagelist">
<ul id="aaiu-ul-list" class="aaiu-upload-list"></ul>
</div>
<a id="aaiu-uploader" class="aaiu_button" href="#"><?php
_e('*Select Documents (mandatory)','wpestate');?></a>
<input type="hidden" name="docid" id="docid" value="<?php echo
$docid;?>">
</div>
</div>
</div>