VPS参考测评推荐
专注分享VPS主机优惠信息
衡天云优惠活动
华纳云最新优惠促销活动
jtti最新优惠促销活动

如何上传wordpress前端图片(如何在wordpress中上传文件)

locvps
主机参考:VPS测评参考推荐/专注分享VPS服务器优惠信息!若您是商家可以在本站进行投稿,查看详情!此外我们还提供软文收录、PayPal代付、广告赞助等服务,查看详情!
我们发布的部分优惠活动文章可能存在时效性,购买时建议在本站搜索商家名称可查看相关文章充分了解该商家!若非中文页面可使用Edge浏览器同步翻译!PayPal代付/收录合作

wordpress教程专栏介绍如何上传WordPress前端图片。

WordPress前端图片上传最近有个研究项目需要在wordpress前端上传用户头像,网上查了一些资料!解决了这个问题!1.第一步是在需要的地方添加一个文件上传框。

lt表单操作= "method = 帖子 enctype = 多部分/格式数据 gt lt输入类型= 文件 id = 文件 name = 文件[] ;倍数= 多重 接受= image/* ;/ gt; lt输入类型= 提交 name = 提交 value = 上传!"/ gt; lt/form gt;2.处理图片。

$ post = get _ post(13);//测试if($ _ files){ $ files = $ _ files[ # 39;文件 # 39;];$ count = count($ files[ # 39;姓名 # 39;]);foreach($files[ # 39;姓名 # 39;]as $ key = gt;$ value){ if($files[ # 39;姓名 # 39;][$ key]){ $ file = array( # 39;姓名 # 39;= gt$ files[ # 39;姓名 # 39;][$key], # 39;类型 # 39;= gt$ files[ # 39;类型 # 39;][$key], # 39;tmp _ name # 39= gt$ files[ # 39;tmp _ name # 39][$key], # 39;错误 # 39;= gt$ files[ # 39;错误 # 39;][$key], # 39;尺寸 # 39;= gt$ files[ # 39;尺寸 # 39;][$ key]);$ _ FILES = array( ;文件 = gt$ file);foreach($ _ FILES as $ file = gt;$ array){ $ new upload = insert _ attachment($ file,$ post- gt;ID);//此方法将文章附加到ID为13的文章。如果你不想把它插入文章中,你可以把它留为空白" }}} }3:在functions.php文件中添加函数

Insert_attachment如果该函数的第二个参数为空,则不会附加到文章中的图片上。函数insert _ attachment($ file _ handler,$post_id,$ setthumb = # 39假 # 39;){ global $ wpdb//如果($ _ FILES[$ file _ handler][ # 39;错误 # 39;] != = UPLOAD _ ERR _ OK)_ _ return _ false();require_once(ABSPATH。"WP-管理 。'/includes/image . PHP # 39;);require_once(ABSPATH。"WP-管理 。'/includes/file . PHP # 39;);require_once(ABSPATH。"WP-管理 。'/includes/media . PHP # 39;);$ attach _ id = media _ handle _ upload($ file _ handler,$ post _ id);$ image _ URL = WP _ get _ attachment _ image _ src($ attach _ id, # 39;满 # 39;);if($ setthumb){ $ wpdb- gt;插入($ wpdb- gt;前缀。'postmeta # 39,数组( # 39;post _ id # 39= gt$post_id, # 39;meta _ key # 39= gt'wpcf-VI-img # 39;, 'meta _ value # 39= gt$ image _ URL[0]);} return $ attach _ id}4:参考方法

$ image _ URL = WP _ get _ attachment _ image _ src($ attach _ id, # 39;满 # 39;);//由于页面刷新的问题,直接在页面上使用这个方法效果不好!这个方法的函数需要在函数中构造。//文章中循环特征图片的方法。如果文章附有图片,可以用这个方法批量输出!$imagess=get_post_meta(13, # 39;wpcf-VI-img # 39;,假);foreach($ imagess as $ images){ echo $ images;}以上是如何上传wordpress前端图片的细节。更多请关注主机参考其他相关文章!

这几篇文章你可能也喜欢:

本文由主机参考刊发,转载请注明:如何上传wordpress前端图片(如何在wordpress中上传文件) https://zhujicankao.com/84177.html

【腾讯云】领8888元采购礼包,抢爆款云服务器 每月 9元起,个人开发者加享折上折!
打赏
转载请注明原文链接:主机参考 » 如何上传wordpress前端图片(如何在wordpress中上传文件)
主机参考仅做资料收集,不对商家任何信息及交易做信用担保,购买前请注意风险,有交易纠纷请自行解决!请查阅:特别声明

评论 抢沙发

评论前必须登录!