Server : LiteSpeed System : Linux nl-srv-web1396.main-hosting.eu 4.18.0-553.83.1.lve.el8.x86_64 #1 SMP Wed Nov 12 10:04:12 UTC 2025 x86_64 User : u107206879 ( 107206879) PHP Version : 7.2.34 Disable Function : NONE Directory : /home/u107206879/domains/escort46.de/public_html/admin/service/ |
<?php
require "../db_connection.php";
include "../sessioncheck.php";
$response = array();
//function to create thumbnail
function create_thumb($target,$ext,$thumb_path,$w,$h){
list($w_orig,$h_orig)=getimagesize($target);
$scale_ratio=$w_orig/$h_orig;
if(($w/$h)>$scale_ratio)
$w=$h*$scale_ratio;
else
$h=$w/$scale_ratio;
if($w_orig<=$w){
$w=$w_orig;
$h=$h_orig;
}
$img="";
$info = getimagesize($target);
if($info['mime']=="image/gif")
$img=imagecreatefromgif($target);
else if($info['mime']=="image/png")
$img=imagecreatefrompng($target);
else if($info['mime']=="image/jpeg")
$img=imagecreatefromjpeg($target);
$tci=imagecreatetruecolor($w,$h);
imagecopyresampled($tci,$img,0,0,0,0,$w,$h,$w_orig,$h_orig);
imagejpeg($tci,$thumb_path,80);
imagedestroy($tci);
}//end function create_thumb()
//Compress Function
function compress($source, $destination, $quality) {
list($w,$h)=getimagesize($source);
$info = getimagesize($source);
if ($info['mime'] == 'image/jpeg'){
$image = imagecreatefromjpeg($source);
imagejpeg($image, $destination, $quality);
}elseif ($info['mime'] == 'image/gif') {
$image = imagecreatefromgif($source);
imagejpeg($image, $destination, $quality);
}elseif ($info['mime'] == 'image/png') {
$image = imagecreatefrompng($source);
$tci=imagecreatetruecolor($w,$h);
imagealphablending($tci, false);
imagesavealpha($tci, true);
imagecopyresampled($tci,$image,0,0,0,0,$w,$h,$w,$h);
imagepng($tci,$destination,1);
}
return true;
}
foreach ($_FILES["myFile"]["error"] as $key => $error) {
if($error == 0){
$tmp_name = $_FILES['myFile']['tmp_name'][$key];
$path = "../../user_images/";
$thumb_path = "../../thumbnails/";
$name = $_FILES["myFile"]["name"][$key];
$size = $_FILES['myFile']['size'][$key];
$type = $_FILES['myFile']['type'][$key];
$ext = strtolower(substr($name, strrpos($name, '.') +1));
$name = time()."_".rand(0,999999).".".$ext;
$thumb_1 = '178_'.$name;
$thumb_2 = '310_'.$name;
if(($ext=='jpg' || $ext=='jpeg' || $ext=='png' || $ext=='gif')&&($type=='image/jpeg' || $type=='image/png' || $type=='image/gif'))
{
if(compress($_FILES['myFile']['tmp_name'][$key], $path.$name, 80)){
mysqli_query($connection, "INSERT INTO images (ad_id,em_id,photo,is_profile) VALUES (".$_POST['adid'].",".$_POST['userid'].",'".$name."',0)");
create_thumb($path.$name,$ext,$thumb_path.$thumb_1,178,178);
create_thumb($path.$name,$ext,$thumb_path.$thumb_2,510,510);
$response['images'][] = array('id'=>mysqli_insert_id($connection), 'src'=>MAIN_URL."/user_images/".$name);
}
}
}
}
$response['status'] = 1;
echo json_encode($response, true);
?>