Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 675889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:52:04+00:00 2026-05-14T00:52:04+00:00

The below code seems like it should work; however, the blob in the database

  • 0

The below code seems like it should work; however, the blob in the database only contains 0 after the function is run. Does the below code look accurate? If not how can I fix it?

$tmpName  = $_FILES['picture']['tmp_name'];

$fp      = fopen($tmpName, 'r');
$binary = fread($fp, filesize($tmpName));
fclose($fp);

$originalImage = imagecreatefromstring($binary);
$tempImage = imagecreate(100,100);
imagecopyresized($tempImage,$originalImage,0,0,0,0,100,100);
ob_start();
imageJPEG($tempImage);
$thumbnail = ob_get_contents();
ob_end_clean();

$wpdb->query("UPDATE ".$wpdb->prefix."items SET picture = $thumbnail WHERE id=$id'");

Thank :)!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:52:05+00:00Added an answer on May 14, 2026 at 12:52 am

    You would probably want to send the blob/picture data to your DB as hex, as it is the most efficient method:

    if ( is_uploaded_file($_FILES['picture']['tmp_name']) ) {
        $originalImage = imagecreatefromjpeg($_FILES['picture']['tmp_name']);
        $thumbImage = imagecreatetruecolor(100, 100);
        imagecopyresized($thumbImage, $originalImage, 0, 0, 0, 0, 100,100);
    
        imagedestroy($originalImage); // Free the memory as soon as possible
    
        ob_start();
        imagejpeg( $thumbImage, NULL, JPEG_QUALITY);
        $thumbData = ob_get_contents();
        ob_end_clean();
    
        imagedestroy($thumbImage);
    
    
        $wpdb->query("UPDATE ".$wpdb->prefix."items SET picture = x'".bin2hex($thumbData)."' WHERE id=$id'");
    }
    

    note the x'".bin2hex($thumbData)."' the x marks the contents of the string as hex.

    Please note:
    There is a lot of debate about if it is a good idea to store images in the Database or not. The general consensus is that it is a bad idea, except when:

    1. Your images are less than 2MB in size
    2. You intend to store no more tan 1GB in total (and even at 1GB you are stretching it).

    In all other cases, store the image on disk and store the location of said image in your database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 514k
  • Answers 514k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The HasMorePages property indicates to silverlight printing that you have… May 16, 2026 at 6:19 pm
  • Editorial Team
    Editorial Team added an answer Tutorial: Networking and Bonjour on iPhone May 16, 2026 at 6:19 pm
  • Editorial Team
    Editorial Team added an answer You could do it in a line with LINQ. One… May 16, 2026 at 6:19 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Update: I checked the answer before I fully tested it still does not work.
I would like to present multiple modal views in sequence (e.g. show confirmation page
I've been investigating frame breaking code recently and have come across some really bizarre
In the following code sample I have an Async Calculator class. This is injected
On a site I run, I have 404's and 500 errors mapped to redirect
I've got a generated MD5-hash, which I would like to compare to another MD5-hash
I have a Drupal view which should output a video player using flash. I
Background: I'm using Google's protobuf , and I would like to read/write several gigabytes
I'm currently writing myself a little C# back up program. I'm using a standard
I am trying to re-write an existing system with objects. I have created a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.