Hi, My script works but not the way I would like it to.
$file = $_FILES['content']['tmp_name'];
if
(!isset($file))
echo "please select an image.";
else {
$content = addslashes (file_get_contents ($_FILES['content']['tmp_name']));
$content_name = addslashes ($_FILES['content']['name']);
$content_size = getimagesize ($_FILES['content'] ['tmp_name']);
$user = $row_Recordset1['user_id'];
if (!$content_size)
echo "Thats not an image";
else {
$colname_Recordset1 = "-1";
if (isset($_SESSION['MM_Username'])) {
$colname_Recordset1 = $_SESSION['MM_Username'];
}
//
// define constants
define('THUMBS_DIR','C:/folder/' );
define('MAX_WIDTH', 200);
define('MAX_HEIGHT', 200);
// process the uploaded image
if (is_uploaded_file($_FILES['content']['tmp_name'])) {
$original = $_FILES['content']['tmp_name'];
// begin by getting the details of the original
list($width, $height, $type) = getimagesize($original);
// calculate the scaling ratio
if ($width <= MAX_WIDTH && $height <= MAX_HEIGHT) {
$ratio = 1;
}
elseif ($width > $height) {
$ratio = MAX_WIDTH/$width;
}
else {
$ratio = MAX_HEIGHT/$height;
}
// strip the extension off the image filename
$imagetypes = array('/\.gif$/', '/\.jpg$/', '/\.jpeg$/', '/\.png$/');
$name = preg_replace($imagetypes, '', basename($_FILES['image']['name']));
// create an image resource for the original
switch($type) {
case 1:
$source = @ imagecreatefromgif($original);
if (!$source) {
$result = 'Cannot process GIF files. Please use JPEG or PNG.';
}
break;
case 2:
$source = imagecreatefromjpeg($original);
break;
case 3:
$source = imagecreatefrompng($original);
break;
default:
$source = NULL;
$result = 'Cannot identify file type.';
}
// make sure the image resource is OK
if (!$source) {
$result = 'Problem copying original';
}
else {
// calculate the dimensions of the thumbnail
$thumb_width = round($width * $ratio);
$thumb_height = round($height * $ratio);
// create an image resource for the thumbnail
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
// create the resized copy
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height);
// save the resized copy
switch($type) {
case 1:
if (function_exists('imagegif')) {
$success = imagegif($thumb, THUMBS_DIR.$name.'_thb.gif');
$thumb_name = $name.'_thb.gif';
}
else {
$success = imagejpeg($thumb, THUMBS_DIR.$name.'_thb.jpg', 50);
$thumb_name = $name.'_thb.jpg';
}
break;
case 2:
$success = imagejpeg($thumb, THUMBS_DIR.$name.'_thb.jpg', 100);
$thumb_name = $name.'_thb.jpg';
break;
case 3:
$success = imagepng($thumb, THUMBS_DIR.$name.'_thb.png');
$thumb_name = $name.'_thb.png';
}
if ($success) {
$result = "$thumb_name created";
}
else {
$result = 'Problem creating thumbnail';
}
// remove the image resources from memory
imagedestroy($source);
imagedestroy($thumb);
}
}
//
//include('includes/create_thumb3.inc.php');
if (!$insert = mysql_query("INSERT INTO mystuff.image (image_id, user_id, name,content)VALUES('', '$user','$content_name','$content')"))
echo (mysql_error());
}
}
?>
The image that goes into the folder is resized but the copy that is inserted into database is not. I see why it's not working. $content is the image beforre resize. The problem is that I don't know how to get it to work. Any help. I would like to eliminate the folder and put resized image into database. Thanks