It actually really slow to keep binary in your database, I do not recommend doing it. I would definately recommend you store the images on your server and put a path fieled in your database. It’s a little hard to keep track of, but it’s much faster.
Edit: after reading your last post i should tell you, i am really familiar with doing this, i even have a some code for you to play with:
<?php
$MAXIMUM_FILESIZE = 1024 * 1500; // 200KB
$MAXIMUM_FILE_COUNT = 1000; // keep maximum 1000 files on server
$filename = $_GET['filename'];
$galleryname = $_GET['gallery'];
if ($_FILES['Filedata']['size'] <= $MAXIMUM_FILESIZE) {
unset($_FILES['Filedata']['name']);
$_FILES['Filedata']['name'] = $filename.".jpg";
mkdir("./gallery/".$galleryname."/");
mkdir("./gallery/".$galleryname."/full/");
mkdir("./gallery/".$galleryname."/thumbs/");
move_uploaded_file($_FILES['Filedata']['tmp_name'], "./temporary/".$_FILES['Filedata']['name']);
rename("./temporary/".$_FILES['Filedata']['name'], "./gallery/".$galleryname."/full/".$_FILES['Filedata']['name']);
};
$fullsize = "./gallery/".$galleryname."/full/".$_FILES['Filedata']['name'];
$thumbsize = "./gallery/".$galleryname."/thumbs/".$_FILES['Filedata']['name'];
// The file
$filein = $fullsize; // File in
$fileout = $thumbsize; // Fileout - optional
$imagethumbsize_w = 95; // thumbnail size (area cropped in middle of image)
$imagethumbsize_h = 64; // thumbnail size (area cropped in middle of image)
resize_then_crop( $filein,$fileout,$imagethumbsize_w,
$imagethumbsize_h,/*rgb*/"255","255","255");
function resize_then_crop( $filein,$fileout,$imagethumbsize_w,$imagethumbsize_h,$red,$green,$blue){
// Get new dimensions
list($width, $height) = getimagesize($filein);
$new_width = $width * $percent;
$new_height = $height * $percent;
if(preg_match("/.jpg/i", "$filein"))
{
$format = 'image/jpeg';
};
if (preg_match("/.gif/i", "$filein"))
{
$format = 'image/gif';
};
if(preg_match("/.png/i", "$filein"))
{
$format = 'image/png';
};
switch($format)
{
case 'image/jpeg':
$image = imagecreatefromjpeg($filein);
break;
case 'image/gif';
$image = imagecreatefromgif($filein);
break;
case 'image/png':
$image = imagecreatefrompng($filein);
break;
};
$width = $imagethumbsize_w ;
$height = $imagethumbsize_h ;
list($width_orig, $height_orig) = getimagesize($filein);
if ($width_orig < $height_orig) {
$height = ($imagethumbsize_w / $width_orig) * $height_orig;
} else {
$width = ($imagethumbsize_h / $height_orig) * $width_orig;
};
if ($width < $imagethumbsize_w)
//if the width is smaller than supplied thumbnail size
{
$width = $imagethumbsize_w;
$height = ($imagethumbsize_w/ $width_orig) * $height_orig;;
};
if ($height < $imagethumbsize_h)
//if the height is smaller than supplied thumbnail size
{
$height = $imagethumbsize_h;
$width = ($imagethumbsize_h / $height_orig) * $width_orig;
}
$thumb = imagecreatetruecolor($width , $height);
$bgcolor = imagecolorallocate($thumb, $red, $green, $blue);
ImageFilledRectangle($thumb, 0, 0, $width, $height, $bgcolor);
imagealphablending($thumb, true);
imagecopyresampled($thumb, $image, 0, 0, 0, 0,
$width, $height, $width_orig, $height_orig);
$thumb2 = imagecreatetruecolor($imagethumbsize_w , $imagethumbsize_h);
// true color for best quality
$bgcolor = imagecolorallocate($thumb2, $red, $green, $blue);
ImageFilledRectangle($thumb2, 0, 0,
$imagethumbsize_w , $imagethumbsize_h , $white);
imagealphablending($thumb2, true);
$w1 =($width/2) - ($imagethumbsize_w/2);
$h1 = ($height/2) - ($imagethumbsize_h/2);
imagecopyresampled($thumb2, $thumb, 0,0, $w1, $h1,
$imagethumbsize_w , $imagethumbsize_h ,$imagethumbsize_w, $imagethumbsize_h);
// Output
//header('Content-type: image/gif');
//imagegif($thumb); //output to browser first image when testing
if ($fileout !="")imagegif($thumb2, $fileout); //write to file
header('Content-type: image/gif');
imagegif($thumb2); //output to browser
};
//------start thumbnailer
$thumbsize=300;
$imgfile = $fullsize;
header('Content-type: image/jpeg');
list($width, $height) = getimagesize($imgfile);
$imgratio=$width/$height;
if ($imgratio>1){
$newwidth = $thumbsize;
$newheight = $thumbsize/$imgratio;}
else{
$newheight = $thumbsize;
$newwidth = $thumbsize*$imgratio;}
$thumb = ImageCreateTrueColor($newwidth,$newheight);
$source = imagecreatefromjpeg($imgfile);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb,$fullsize,100);
?>