【发布时间】:2016-01-24 12:05:31
【问题描述】:
好的,这是我的代码 - 标准代码,如果我只是选择现有图像就可以使用
jQuery(function($){
var file_frame;
$('#upload-button').on( 'click', function( e ){
e.preventDefault();
// If the media frame already exists, reopen it.
if ( file_frame ) {
file_frame.open();
return;
}
// Create a new media frame
file_frame = wp.media({
title: 'Select or Upload Media Of Your Chosen Persuasion',
button: {
text: 'Use this media'
},
multiple: false // Set to true to allow multiple files to be selected
});
file_frame.on('open', function(){
console.log("inside open");
});
file_frame.on('update', function(){
console.log("inside update");
});
file_frame.on('select', function(){
// This will return the selected image from the Media Uploader, the result is an object
var uploaded_image = file_frame.state().get('selection').first();
// We convert uploaded_image to a JSON object to make accessing it easier
// Output to the console uploaded_image
console.log(uploaded_image);
var image_url = uploaded_image.toJSON().url;
// Let's assign the url value to the input field
$('#image-url').val(image_url);
});
file_frame.open();
});
});
但是,如果我将图像拖放到其中,则图像已上传,但返回错误 “上传出错,请稍后重试。”
我错过了什么,我假设它对现有媒体选择窗口进行了某种刷新,而我的谷歌搜索没有出现任何内容。
干杯
编辑
我已经尝试了几种方法来让上传的图片在上传后显示在媒体框架中。没有太大的成功。 正如我所说,图像似乎已上传并添加到媒体库,但我错过了刷新或重新加载框架以显示图像。
任何人有经验或知道其他地方可以去看看吗?
【问题讨论】:
-
是正面还是背面?
-
后端表单。特别是我正在写的一个插件。
标签: php jquery wordpress plugins upload