In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to upload wordpress front-end pictures, the article is very detailed, has a certain reference value, interested friends must read it!
Upload pictures on wordpress frontend.
Recently, a research project needs to upload user profile photos on the front end of wordpress, and look up some information on the Internet! Solved the problem!
1: first of all, add the file upload box where you need it.
2: process the picture
$post=get_post (13); / if for testing ($_ 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); / / this method appends articles to articles with ID 13. If you do not want to insert into the article, it can be empty ""}}.
3: add function to functions.php file
Insert_attachment the second argument to this function will not be appended to the picture in the article if it is empty. 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: reference method
$image_url = wp_get_attachment_image_src ($attach_id,'full'); / / it doesn't work to use this method directly on the page because of page refresh problems! You need to construct the functionality of this method in the function. / / the method of cycling the feature pictures in the article, if you attach the picture to the article, you can use this method to output in batch! Foreach ($imagess as $images) {echo $images;} is all the contents of this article entitled "how to upload wordpress front-end images". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.