I have the following code to move file to folder and then with that path I am cropping the image on submitting the form.
<?php
if(isset($_POST['submit']))
{
header('Content-type: image/jpeg');
move_uploaded_file($_FILES['image_file'] \
['tmp_name'],'media/'.$_FILES['image_file']['name']);
$path='media/'.$_FILES['image_file']['name'];
$maxsize=200;
$sourcefile=$path;
$imgcomp=0;
$g_imgcomp=100-$imgcomp;
if(file_exists($sourcefile))
{
$g_is=getimagesize($sourcefile);
if($g_is[0] <= $maxsize && $g_is[1] <= $maxsize)
{
$new_width=$g_is[0];
$new_height=$g_is[1];
}
else
{
$w_adjust = ($maxsize / $g_is[0]);
$h_adjust = ($maxsize / $g_is[1]);
if($w_adjust <= $h_adjust)
{
$new_width=($g_is[0]*$w_adjust);
$new_height=($g_is[1]*$w_adjust);
}
else
{
$new_width=($g_is[0]*$h_adjust);
$new_height=($g_is[1]*$h_adjust);
}
}
$image_type = strtolower(strrchr($sourcefile, "."));
switch($image_type)
{
case '.jpg':
$img_src = imagecreatefromjpeg($sourcefile);
break;
case '.jpeg':
$img_src = imagecreatefromjpeg($sourcefile);
break;
case '.png':
$img_src = imagecreatefrompng($sourcefile);
break;
case '.gif':
$img_src = imagecreatefromgif($sourcefile);
break;
default:
echo("Error Invalid Image Type");
die;
break;
}
$img_dst=imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $new_width,
$new_height, $g_is[0], $g_is[1]);
imagejpeg($img_dst);
imagedestroy($img_dst);
$src_img = $image_create($sourcefile);
rename('$src_img', 'media1/$src_img');
?>
<img src="$src_img">// image is desplaying
<?php }
else
{
return false;
}
}
?>
Now how can I save the cropped image back to the folder(new/old) and save the path in data base?