• Hi, I’m new to developing with wordpress.
    I have a form where I upload to an image database, but when I try to display the image, does not work.

    This is the code where I insert the image to the database:

    <?php
    global $wpdb;
    $image = addslashes(file_get_contents($_FILES['file']['tmp_name']));
    $wpdb->insert('image' => $image);
    ?>

    And, this is the code where I try display the image:

    <?php
    global $wpdb;
    $get_image = $wpdb->get_row("SELECT image FROM clientes WHERE id = 1");
    $image = $get_image->image;
    echo '<img src="data:image/jpeg;base64,'.base64_encode($contenido_foto).'">';
    ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • Have you checked the database to see if the image gets inserted?
    The insert code doesn’t look corect. Please check codex page here to get a better idea on how wpdb->insert works.

    As in the codex page, you use it like:
    <?php $wpdb->insert( $table, $data, $format ); ?>

    From what I can see you code misses the $table in which the imag to be saved ($table and $data are mandatory!)

    Also usually tables associated to WordPress have a prefix so make sure your image is queried from the correct table clients vs wp_clients or other forms.

    Thread Starter felipe.91

    (@felipe91)

    sorry, the insert is:

    $wpdb->insert('clientes', array('image'=>$image));

    What do you have in your database?

    Do you get an entry in your database when you save the file?

    What actually happens that “does not work”?

    You get no output? – check html with inspect mode to see exactly what gets echoed

    Is the website public accessible? can you link to it?

    Thread Starter felipe.91

    (@felipe91)

    Thanks for the answers, but I decided to save the images on the server.

    if it works then it’s perfect! ??
    have a nice one!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Inserting and displaying blob image’ is closed to new replies.