if ((($_FILES['myfile']['type']) != "image/jpeg" ) &&
(($_FILES['myfile']['type']) != "image/jpg") &&
(($_FILES['myfile']['type']) != "image/pjpeg") &&
(($_FILES['myfile']['type']) != "image/jpe" ))
{
$result = 0 ;
$message = $_FILES['myfile']['type'] . "<br />Wrong type of file" ;
} else {
if( $_FILES['myfile']['size'] == 0 || $_FILES['orig_file']['size'] > 25360000 ) {
$result = 0 ;
$message = $_FILES['myfile']['size'] . "File is either Zero size or too large" ;
} else {
if (((!is_dir($store_dir)) || (!is_dir($thumb_dir)) || (!is_dir($blog_dir)) ) ){
$result = 0 ;
$message = "Destination Specified is not a directory" ;
} else {
$target_path = $store_dir . $filename ;
if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
$result = 1;
$message = "<br />Filename " . $filename ;
// Max height and width
$max_width = $THUMB_IMAGE_WIDTH ;
$max_height = $THUMB_IMAGE_HEIGHT ;
$full_max_width = $MAIN_IMAGE_WIDTH ;
$full_max_height = $MAIN_IMAGE_HEIGHT ;
$blog_max_width = $BLOG_IMAGE_WIDTH ;
$blog_max_height = $BLOG_IMAGE_HEIGHT ;
$full = $store_dir . $filename ;
$blog = $blog_dir . $filename ;
$thumb = $thumb_dir . $filename ;
$size = GetImageSize($full); // Read the size
$width = $size[0];
$height = $size[1];
// Proportionally resize the image to the
// max sizes specified above
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
$full_x_ratio = $full_max_width / $width;
$full_y_ratio = $full_max_height / $height;
$blog_x_ratio = $blog_max_width / $width;
$blog_y_ratio = $blog_max_height / $height;
// if necessary resize the uploaded image so that
// the MAX dimension in either direction is not breached.
if( ($width <= $full_max_width) && ($height <= $full_max_height) )
{
$full_width = $width;
$full_height = $height;
}
elseif (($full_x_ratio * $height) < $full_max_height)
{
$full_height = ceil($full_x_ratio * $height);
$full_width = $full_max_width;
}
else
{
$full_width = ceil($full_y_ratio * $width);
$full_height = $full_max_height;
}
// Create the new image!
$src = imagecreatefromjpeg($full);
$dst = imagecreatetruecolor($full_width, $full_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $full_width, $full_height, $width, $height);
imagejpeg($dst, $store_dir . $filename, IMAGE_QUALITY);
// Destroy the images
// don't destroy the uploaded image until thumbnail has been created/ / ImageDestroy($src);
imagedestroy($dst);
// sort out the thumbnail images
if( ($width <= $max_width) && ($height <= $max_height) )
{
$tn_width = $width;
$tn_height = $height;
}
elseif (($x_ratio * $height) < $max_height)
{
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else
{
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
$dst = imagecreatetruecolor($tn_width, $tn_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
imagejpeg($dst, $thumb_dir . $filename, IMAGE_QUALITY);
imagedestroy($dst);
// sort out the blog images
if ($_POST['blog'] == 1) {
if( ($width <= $blog_max_width) && ($height <= $blog_max_height) )
{
$blog_width = $width;
$blog_height = $height;
}
elseif (($blog_x_ratio * $height) < $blog_max_height)
{
$blog_height = ceil($blog_x_ratio * $height);
$blog_width = $blog_max_width;
}
else
{
$blog_width = ceil($blog_y_ratio * $width);
$blog_height = $blog_max_height;
}
$dst = imagecreatetruecolor($blog_width, $blog_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $blog_width, $blog_height, $width, $height);
imagejpeg($dst, $blog_dir . $filename, IMAGE_QUALITY);
imagedestroy($dst);
}
imagedestroy($src);
}
}
}
}