i am trying to upload image it is uploaded successfully but when i tried to access it in phpmysql the link is somethig like this : http://localhost/job/?attachment_id=40

i want to store this image url like this: http://localhost/job/wp-content/uploads/2015/05/Koala.jpg

here is code to upload image:

if(!empty($_FILES['photo_rcb'])) {
                                $file   = $_FILES['photo_rcb'];
                                $upload = wp_handle_upload($file, array('test_form' => false));
                              //  print_r($upload);exit;
                                if(!isset($upload['error']) && isset($upload['file'])) {
                                    $filetype   = wp_check_filetype(basename($upload['file']), null);
                                    $title      = $file['name'];
                                    $ext        = strrchr($title, '.');
                                    $title      = ($ext !== false) ? substr($title, 0, -strlen($ext)) : $title;
                                    $attachment = array(
                                        'post_mime_type'    => $wp_filetype['type'],
                                        'post_title'        => addslashes($title),
                                        'post_content'      => '',
                                        'post_status'       => 'inherit',
                                        'post_author'       => $user_id

                                        $attach_key = 'document_file_id';
                                        $attach_id  = wp_insert_attachment($attachment, $upload['file']);

                                        update_user_meta($user_id,'photo_rcb', $attach_id);
  • What are you trying to do exactly? Retrieve the URL?
    – Syed Priom
    May 21 '15 at 4:58

Images should upload in that format when using wp_handle_upload. It is unclear exactly how you are getting http://localhost/job/?attachment_id=40

I would suggest having something similar to the Handling the File Upload section of this post:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.