OverLord Shell
<?php
/*
@Purpose: Update status of product
@Author: Rajahree
@CreatedOn: 15 April 2016
@ModifiedOn: 15 April 2016
*/
error_reporting(0);
session_start();
include("db/conn.php");
if(!isset($_SESSION['company_id']) || !isset($_SESSION['company_name'])){session_destroy();header("location:login.php");}
if(!in_array($_SESSION['loggedin_user'],array('admin','company'))){header("location:404.php");}
$old_productimg = $_POST['old_productimg'];
$target_dir = "../uploads/products/";
//getting Photo info
$fname=$_FILES['productimg']['name'];
if(!empty($fname)){
$ftype=$_FILES['productimg']['type'];
if($_FILES['productimg']['error']==1){echo "Photo upload error.";exit;}
else{
if($_FILES['productimg']['size'] < 2*1024*1024){
if($ftype=="image/jpeg" || $ftype=="image/pjpeg" || $ftype=="image/gif" || $ftype=="image/png"){
@$ext=explode('.',basename($fname));
@$ext=end($ext);
$uploadprodimg[0]=$_SESSION['company_id']."-prod-".date('YmdHis').".".$ext;
}
else{echo "Photo type error. Only JPG, PNG and GIF allowed.";exit;}
}
else{echo "Photo size error. Max size is 2 MB.";exit;}
}
}else{echo "Please upload a Photo.";exit;}
$photo_data = array(
'photo_path' => $uploadprodimg[0],
'modifiedby'=> $_SESSION['company_id'],
);
$editresult = dbRowUpdate('busdir_product_photo', $photo_data,'photo_id = '.$_POST['photo_id'].'');
if($editresult=='success'){
//deleting old photo
@unlink($target_dir.$old_productimg);
@unlink($target_dir."thumbs/".$old_productimg);
//moving uploaded photo to its location
if(@move_uploaded_file($_FILES['productimg']['tmp_name'], $target_dir.$uploadprodimg[0])){
//Get width and height of original image & creating thumbnail
$size=getimagesize($target_dir.$uploadprodimg[0]);
$origWidth=$size[0];
$origHeight=$size[1];
if($origWidth>200 && $origHeight>200){
//Change dimensions
$aspectratio=$origWidth/$origHeight;
if($aspectratio>1){
$resizedWidth=200;
$resizedHeight=round(($resizedWidth * $origHeight) / $origWidth);
}
else{
$resizedHeight=200;
$resizedWidth=round(($resizedHeight * $origWidth) / $origHeight);
}
//Load the source image
if($ftype=="image/jpeg" || $ftype=="image/pjpeg") $imageSource=imagecreatefromjpeg($target_dir.$uploadprodimg[0]);
if($ftype=="image/gif") $imageSource=imagecreatefromgif($target_dir.$uploadprodimg[0]);
if($ftype=="image/png") $imageSource=imagecreatefrompng($target_dir.$uploadprodimg[0]);
$imageOutput=imagecreatetruecolor($resizedWidth, $resizedHeight);
$result=imagecopyresampled($imageOutput, $imageSource, 0, 0, 0, 0, $resizedWidth, $resizedHeight, $origWidth, $origHeight);
//Write out the image file with the quality value
$imagePath="../uploads/products/thumbs/".$uploadprodimg[0];
if($ftype=="image/jpeg" || $ftype=="image/pjpeg")$result=imagejpeg($imageOutput, $imagePath, 70);
elseif($ftype=="image/gif")$result=imagegif($imageOutput, $imagePath, 70);
elseif($ftype=="image/png")$result=imagepng($imageOutput, $imagePath, 70);
}
else{
@copy($target_dir.$uploadprodimg[0],$target_dir."thumbs/".$uploadprodimg[0]);
}
}
}
echo $editresult;
$connection->close();
?>
xRyukZ - Copyright 2k19