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 :)!
You would probably want to send the blob/picture data to your DB as hex, as it is the most efficient method:
note the
x'".bin2hex($thumbData)."'thexmarks 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:
In all other cases, store the image on disk and store the location of said image in your database.