Friday, February 14, 2014
resize image during upload
if(isset($_FILES['add_image1'])){
$tt=time();
$target_path = "../product_image/".$tt;
$target_path = $target_path . basename( $_FILES["add_image1"]['name']);
$pn="product_image/".basename( $_FILES["add_image1"]['name']);
$ch=strtolower(substr($pn, strrpos($pn,".")+1));
if($ch=="jpg" or $ch=="png" or $ch=="jpeg" or $ch=="gif"){
$uploadedfile = $_FILES['add_image1']['tmp_name'];
//$size=filesize($_FILES['add_image1']['tmp_name']);
if (!empty($uploadedfile)){
$info = getimagesize($uploadedfile);
if($ch=="jpg" || $ch=="jpeg" )
{
if ($info['mime'] == 'image/jpeg')
$src = imagecreatefromjpeg($uploadedfile);
}
else if($ch=="png")
{
if($info['mime'] == 'image/png')
$src = imagecreatefrompng($uploadedfile);
}
else
{
if($info['mime'] == 'image/gif')
$src = imagecreatefromgif($uploadedfile);
}
list($width,$height)=getimagesize($uploadedfile);
$newwidth=100;
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);
if(!empty($src)){
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$filename = "../product_image/".$tt. $_FILES['add_image1']['name'];
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
mysqli_query($db_con,"update table_question set image='".$filename."' where question_id=".$pro_id);
}
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment