G
G
Genri_Rus2020-06-24 18:08:55
WordPress
Genri_Rus, 2020-06-24 18:08:55

How to store image url in database?

I use a regular ajax form to send files as pictures

add_action( 'wp_ajax_comment_upload_image', 'upload_image' );
add_action( 'wp_ajax_nopriv_comment_upload_image', 'upload_image' );

function upload_image() {
  if ( !isset( $_FILES['files'] ) && empty( $_FILES['files'] ) ) {
    return;
  }

  $img = file_get_contents( $_FILES['files']['tmp_name'] );
}

How can the url of the resulting image be stored in the wp_comment_image table?
I will have 2 fields: comment_id (by default null) and url (by default, which is better to set?)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question