我正在编写一个插件,我想使用内置的WordPress媒体上传功能,以便在后端的自定义选项页中上传.doc和.pdf文件。使用jQuery时,我在库中指定了允许的mime,因此,如果用户尝试上传不允许的文件类型,则会跳过该文件,但是如果我在库中签入,则该文件存在。
file_frame = wp.media.frames.file_frame = wp.media({
title: jQuery( this ).data( 'uploader_title' ),
button: {
text: jQuery( this ).data( 'uploader_button_text' ),
},
library: { type: [
'text/plain',
'application/rtf',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/pdf'
] },
multiple: true // Set to true to allow multiple files to be selected
});
file_frame.on( 'select', function() {
var selection = file_frame.state().get('selection');
selection.map( function( attachments ) {
attachments = attachments.toJSON();
$('#docs_upload_form').append('<input type="hidden" name="file[' + attachments.url + ']" value="' + attachments.id + '">');
});
});
file_frame.open();
});
});