脚本宝典收集整理的这篇文章主要介绍了php – WordPress:在管理员选项页面上传图片,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经创建了一个管理选项页面,现在想要添加一个字段以允许用户上传图像.如何将图像上传到wp-content / uploads文件夹.到目前为止,我在一张表中有这个:
<td><input name="logo_image" tyPE="file" id="logo_image" value="" /></td>
if(function_exists( 'wp_enqueue_media' )){ wp_enqueue_media(); }else{ wp_enqueue_style('thickBox'); wp_enqueue_script('media-upload'); wp_enqueue_script('thickBox'); } <p><strong>Header logo Image URL:</strong><br /> <img class="header_logo" src="<?PHP echo get_option('header_logo'); ?>" height="100" width="100"/> <input class="header_logo_url" type="text" name="header_logo" size="60" value="<?PHP echo get_option('header_logo'); ?>"> <a href="#" class="header_logo_upload">Upload</a> </p> <script> jquery(document).ready(function($) { $('.header_logo_upload').click(function(e) { e.preventDefault(); VAR custom_uploader = wp.media({ tITle: 'Custom Image',button: { text: 'Upload Image' },multiple: false // Set this to true to allow multiple files to be selected }) .on('select',function() { var attachment = custom_uploader.state().get('selection').First().toJSON(); $('.header_logo').attr('src',attachment.url); $('.header_logo_url').val(attachment.url); }) .open(); }); }); </script>
要么
以上是脚本宝典为你收集整理的php – WordPress:在管理员选项页面上传图片全部内容,希望文章能够帮你解决php – WordPress:在管理员选项页面上传图片所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。