Adding metadata to uploaded image.

I am using dropzone.js in my wordpress and it’s working fine. My question is, how can I add metadata to my database, like inserting image name in the user_id column so the images can be called up when the user logs in? Here is the upload code, thanks for any help.

`function dropzonejs_upload() {

if ( !empty( $_FILES ) && wp_verify_nonce( $_REQUEST['my_nonce_field'], 'protect_content' ) ) {

    $uploaded_bits = wp_upload_bits(
        $_FILES['file']['name'],
        null, //deprecated
        file_get_contents( $_FILES['file']['tmp_name'] )
    );

    if ( false !== $uploaded_bits['error'] ) {
        $error = $uploaded_bits['error'];
        return add_action( 'admin_notices', function() use ( $error ) {
                $msg[] = '<div class="error"><p>';
                $msg[] = '<strong>DropzoneJS & WordPress</strong>: ';
                $msg[] = sprintf( __( 'wp_upload_bits failed,  error: "<strong>%s</strong>' ), $error );
                $msg[] = '</p></div>';
                echo implode( PHP_EOL, $msg );
            } );
    }
    $uploaded_file     = $uploaded_bits['file'];
    $uploaded_url      = $uploaded_bits['url'];
    $uploaded_filetype = wp_check_filetype( basename( $uploaded_bits['file'] ), null );

    /*
    etc ...
    */
}
die();
}`

Read more here: Adding metadata to uploaded image.

Leave a Reply

Your email address will not be published. Required fields are marked *