wordpress前端图片如何上传
发表于:2024-10-21 作者:千家信息网编辑
千家信息网最后更新 2024年10月21日,这篇文章主要介绍wordpress前端图片如何上传,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!wordpress前端图片上传最近研究个项目需要在wordpress前端上传用户
千家信息网最后更新 2024年10月21日wordpress前端图片如何上传
这篇文章主要介绍wordpress前端图片如何上传,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
最近研究个项目需要在wordpress前端上传用户头像,在网上查了些资料!解决了这个问题!
1:首先就是在需要的地方添加文件上传框了
2: 对图片进行处理
$post=get_post(13);//测试用if ( $_FILES ) { $files = $_FILES['files']; $count= count($files['name']); foreach ($files['name'] as $key => $value) { if ($files['name'][$key]) { $file = array( 'name' => $files['name'][$key], 'type' => $files['type'][$key], 'tmp_name' => $files['tmp_name'][$key], 'error' => $files['error'][$key], 'size' => $files['size'][$key] ); $_FILES = array("files" => $file); foreach ($_FILES as $file => $array) { $newupload = insert_attachment($file,$post->ID);//此方法将文章附加到ID为13的文章中。如果不想插入到文章可以为空""} } } }
3:在functions.php文件添加功能函数
insert_attachment该函数的第二个参数如果为空将不附加到文章中图片。
function insert_attachment($file_handler,$post_id,$setthumb='false') { global $wpdb; // check to make sure its a successful upload if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false(); require_once(ABSPATH . "wp-admin" . '/includes/image.php'); require_once(ABSPATH . "wp-admin" . '/includes/file.php'); require_once(ABSPATH . "wp-admin" . '/includes/media.php'); $attach_id = media_handle_upload( $file_handler, $post_id );$image_url = wp_get_attachment_image_src( $attach_id,'full' ); if ($setthumb){ $wpdb->insert( $wpdb->prefix . 'postmeta', array( 'post_id' => $post_id, 'meta_key' => 'wpcf-vi-img', 'meta_value' => $image_url[0] )); } return $attach_id;}
4:引用方法
$image_url = wp_get_attachment_image_src( $attach_id,'full' );//由于页面刷新的问题直接在页面使用这个方法是不生效的!需要在函数中构造此方法的功能。//循环文章中的特征图片的方法,如果将图片附加到文章中使用这个方法可以批量输出!$imagess=get_post_meta(13,'wpcf-vi-img',false);foreach($imagess as $images){ echo $images;}
以上是"wordpress前端图片如何上传"这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!
图片
文章
前端
方法
函数
附加
内容
功能
文件
此方法
篇文章
问题
页面
价值
兴趣
参数
地方
头像
小伙
小伙伴
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
计算机通信网络技术期末考试
湖南软件开发五星服务
网络技术宏观环境分析
服务器x3850
怎样用数据库来管理学生
网络安全 v2ex
幻塔安卓服务器没有星岛
网络安全法禁止行为也称为
泉州信息安全特训营网络安全培训
vb 数据库 连接串
多线程访问数据库
瓜州区妇联网络安全宣传
网络安全等级测评师报考方式
电脑无法连接到代理服务器
梦幻西游2不能转区的服务器
计算机网络技术这门课学什么
未来5年网络安全股
网络安全信息化工作方案
jsp 实现数据库登录
港股软件开发搭建好不好
网络安全与执法属于什么学院
badusb网络安全教程
服务器松动怎么办
计算机网络技术艺术
仁王2连不上服务器steam
班级事务管理系统数据库
小米软件开发待遇高吗
奥丁神叛手游服务器太慢
网络技术公司包括电商吗
dell服务器设置两个磁盘