我正在开发我的第一个wordpress插件.它只需要允许用户更改自定义模板中的徽标并更改自定义模板中的颜色方案.
我已经创建了一个管理选项页面,现在想要添加一个字段以允许用户上传图像.如何将图像上传到wp-content/uploads文件夹.到目前为止,我在一张表中有这个:
<td><input name="logo_image" type="file" id="logo_image" value="" /></td>
Run Code Online (Sandbox Code Playgroud)
这是正确的方法吗?如果是这样,我如何将文件定向到正确的文件夹?wordpress是否有自己处理文件上传的方式?
我尝试在wordpress插件中添加多个上传选项,我在插件中重复了这段代码(两次),只更改了id名称.
<script language="JavaScript">
jQuery(document).ready(function($) {
jQuery('#upload_image_button').click(function() {
formfield = jQuery('#upload_image').attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});
window.send_to_editor = function(html) {
imgurl = jQuery('img', html).attr('src');
jQuery('#upload_image').val(imgurl);
tb_remove();
};
});
</script>
<input id="upload_image" style=" margin-left:303px;" type="text" size="36" name="upload_image_template" value="<?php echo get_option('upload_image_template'); ?>" />
<input id="upload_image_button" type="button" value="Browse" />
Run Code Online (Sandbox Code Playgroud)
每当我尝试上传媒体帧的图像并且上传过程成功完成时.但Insert Into Post获取正确的URL但粘贴在不同的输入框中.例如:
1) [text box1] [browse Button]
2) [text box2] [browse button]
Run Code Online (Sandbox Code Playgroud)
当我使用文本框一上传图像时,[insert post]该图像路径显示在[text box 2]
我不确定问题是我的还是该脚本不支持多文件上传选项.