I have finished cropping and resizing an image that user uploaded to my server, now I want to insert it to the database. How should i do?
My problem is can't find the real data to insert to 'data' field.
// File and new size
// May the user upload from POST
$filename = 'test.jpg';
$percent = 0.5;
// Content type
header('Content-Type: image/jpeg');
// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width*$percent;
$newheight = $height*$percent;
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
imagejpeg($thumb);
// What is actually data that I've to insert to 'data' field?
// I think $thumb but it wasn't.
$query = "
INSERT INTO `image` (
`name`, `mime`, `size`, `data`, `created`, `width`, `height`
)
VALUES (
'{$name}', '{$mime}', {$size}, '{....}', NOW(), '{$width}', '{$height}'
)";
Thanks for your help.