image upload and get attachment id in wordpress

Solutions on MaxInterview for image upload and get attachment id in wordpress by the best coders in the world

showing results for - "image upload and get attachment id in wordpress"
Albany
17 May 2017
1/* this function for upload image in wordpress and return attchement id code by joshi yogesh (joshiyogesh0333@gmail.com)*/
2function cst_image_upload($img){
3
4    require_once( ABSPATH . 'wp-admin/includes/image.php' );
5    $attes_id = array();
6    $cnt = count($img['name']);
7    for($i=0;$i<$cnt;$i++)
8    {
9            $name = $img['name'][$i];
10            $type = $img['type'][$i];
11            $tmp_name = $img['tmp_name'][$i];
12            $error = $img['error'][$i];
13            $size = $img['size'][$i] ;
14        
15        $upload_data = array(
16            'name'      => $name,
17            'type'      => $type,
18            'tmp_name'  => $tmp_name,
19            'error'     => $error,
20            'size'      => $size
21            );
22        $uploaded_file = wp_handle_upload($upload_data, array('test_form' => false));
23        // print_r($uploaded_file);
24
25        if (isset($uploaded_file['file'])) {
26            $file_loc   =   $uploaded_file['file'];
27            $file_name  =   basename($upload_data['name']);
28            $file_type  =   wp_check_filetype($file_name);
29
30            $attachment = array(
31                'post_mime_type'    => $file_type['type'],
32                'post_title'        => preg_replace('/\.[^.]+$/', '', basename($file_name)),
33                'post_content'      => '',
34                'post_status'       => 'inherit'
35            );
36
37            $attach_id      =   wp_insert_attachment($attachment, $file_loc);
38            $attach_data    =   wp_generate_attachment_metadata($attach_id, $file_loc);
39            wp_update_attachment_metadata($attach_id, $attach_data);
40            array_push($attes_id,$attach_id);
41        }
42    }
43    return $attes_id;
44}
queries leading to this page
if thumbnail or attachment wordpresswordpress get attachment image idwp get attachment imagewordpress image attachment php detailsimage upload and get attachment id in wordpressget image url by attachment id wordpressupload id get file link wordpressecho wvg get gallery image html 28 24attachment id 2c array 28attachment php wordpress in image urlwordpress image url by attachment idwordpress get image id by filenameget id of attachment image wordpresswordpress wp get attachment imagewp get image attachment idget post attachment image in wordpressget attachment page url of images wordpresswp attachment imagefind uploades images ids wordpress phpget id of attachment images wordpressupload image and get id wordpress programmaticallywordpress get attachments id from gallerywp get image attachment idimg attachments wordpresswordpress get image by idwordpress image attachment detailswp get attachment images idsget ids of attachment images wordpresshow to get image url from id of uploaded in media wordpressget image url from attachment id wordpresswordpress insert image attachmentwordpress upload images access on user idget image url using attachment id wordpresswordpress get attach image by idwordpress get all image attachments of post idwordpress get image path from idwordpress opening image attachment postswordpress functions return ids of attachment imagewordpress url thumbnail attachment getwp get attachment image idimage upload and get id function wordpreswordpress get attachment id from gallerywordpress get thumbnail url by attachment idwordpress echo image from idget ids of images attachment of post type wordpresshow can i get attachment id for wordpress uploaded images 3fwordpress plugin file upload and email attachment formupload file attach id wordpressinsert attachment using url wordpressget attachment image by post id wordpresswordpress get attachment imagewordpress get attachment image urlwordpress get image url from attachment idhow to get attachment image url in wordpresswordpress get attachment id from imagewp get attachment image idwp get attachment image src by post idupload image and get attachment id wordpresswordpress open image attachment postsupload image category wordpressget image by attachment id wordpresswordpress upload image under post idwordpress acf get image upload idwordpress upload ads txtwp get attachment image 28get image according to post id wordpresswordpress display image by idhow to get post image from id wordpressget attachment image wordpresswordpress get image by attachment idwordpress upload directory get with image attachmentwp get attachment image by id in phpwordpress image attachment object php detailsget image attachment by idwp get imagehow to get image attachment id in wordpressget attachment specific thumbnail url in wordpressimage upload and get attachment id in wordpress