| Linux in-mum-web1499.main-hosting.eu 5.14.0-503.40.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Mon May 5 06:06:04 EDT 2025 x86_64 Path : /home/u901718425/public_html/php/ |
| Current File : /home/u901718425/public_html/php/insup.php |
<?php
include("../panel/globale.php");
// file upload function
function files($file){
$target_dir = "";
$target_file = $target_dir .basename($file["name"]);
if(file_exists($target_file)){
unlink($target_file);
}
if (move_uploaded_file($file["tmp_name"],getenv('FILE_CDN_MOVE').$target_file)) {
$out[0] = 'success';
$out[1] = $target_file;
}else{
$out[0] = 'error';
}
return $out;
}
function compress_image($tempPath, $originalPath, $imageQuality){
// Get image info
$imgInfo = getimagesize($tempPath);
$mime = $imgInfo['mime'];
// Create a new image from file
switch($mime){
case 'image/jpeg':
$image = imagecreatefromjpeg($tempPath);
break;
case 'image/png':
$image = imagecreatefrompng($tempPath);
break;
case 'image/gif':
$image = imagecreatefromgif($tempPath);
break;
default:
$image = imagecreatefromjpeg($tempPath);
}
// Save image
imagejpeg($image, $originalPath, $imageQuality);
// Return compressed image
return $originalPath;
}
function files_m($file){
$count = sizeof($file['name']);
for ($i=0; $i < $count; $i++) {
$target_dir = "";
$target_file = $target_dir.'_urbanpillar'.basename($file["name"][$i]);
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
$check = ['jpg','png','jpeg','webp','pdf'];
$img = ['jpg','png','jpeg'];
$tempPath= $file["tmp_name"][$i];
$imageQuality= 60;
$compressedImage = 0;
if(in_array($imageFileType, $img)){
$compressedImage = compress_image($file["tmp_name"][$i], getenv('FILE_CDN_MOVE').$target_file, $imageQuality);
}
if(file_exists($target_file)){
unlink($target_file);
}
if($compressedImage){
$out[0] = 'success';
$out[1][] = $target_file;
}else if ( in_array($imageFileType, $check) && move_uploaded_file($file["tmp_name"][$i],getenv('FILE_CDN_MOVE').$target_file)) {
$out[0] = 'success';
$out[1][] = $target_file;
}else{
$out[0][] = 'error';
}
}
return $out;
}
// error upload function
function errorlog($page,$res,$sql,$db){
$error['id'] = ($db->max("error_log") == NULL? 1 : (int)$db->max("error_log") + 1);
$error['page'] = $_POST['page'];
$error['error'] = $db->sanitize($res);
$error['query'] = $db->sanitize($sql);
$error['status'] = "not solved";
$db->insert("error_log",$error);
}
// image upload function
function image($file){
$target_dir = "";
$target_file = $target_dir.'_urbanpillar'.basename($file["name"]);
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
$check = ['jpg','png','jpeg','webp'];
if(file_exists($target_file)){
unlink($target_file);
}
if (in_array($imageFileType, $check) && move_uploaded_file($file["tmp_name"],getenv('FILE_CDN_MOVE').$target_file)) {
$out[0] = 'success';
$out[1] = $target_file;
}else{
$out[0] = 'error';
}
return $out;
}
if (isset($_POST)) {
if(isset($_POST['multiselect']) && $_POST['multiselect'] !==null){
$_POST['multiselect'] = json_decode($_POST['multiselect']);
}
foreach ($_POST as $key => $value) {
if ($value !="" && $key != 'multiselect' && isset($_POST['multiselect']) && !in_array($key, (array)$_POST['multiselect']) && !preg_match("/image/i", $key) && !preg_match("/doc/i", $key) && $key != 'id' && $key != 'file' && $key != 'image' && $key != 'price_history' && $key != 'page' && $key != 'password' && $key != 'table' && $key != 'avoid' && !in_array($key,(array)$_POST['avoid'])) {
$data[$key] = $db->sanitize($value);
}
if($key == 'image' && preg_match("/http/i", $_POST['image'])){
$data[$key] = $db->sanitize($value);
}
if(isset($_POST['multiselect']) && $key != 'multiselect' && in_array($key, (array)$_POST['multiselect'])){
$data[$key] = (is_array($value)? json_encode($value): $value);
}
}
foreach ($_FILES as $key => $value) {
if(preg_match("/image/i", $key) && isset($_POST['multiselect']) && in_array($key, (array)$_POST['multiselect'])){
if (isset($_FILES[$key]['name']) && $_FILES[$key]['name']!=""){
$s = files_m($_FILES[$key]);
if($s[0] == 'success' ){
$data[$key] = json_encode($s[1]);
}else{
errorlog($_POST['page'],"File Not Uploaded","",$db);
}
}
}else if(preg_match("/image/i", $key)){
if (isset($_FILES[$key]['name']) && $_FILES[$key]['name']!=""){
$s = image($_FILES[$key] );
if($s[0] == 'success' ){
$data[$key] = $s[1];
}else{
errorlog($_POST['page'],"Image Data has been no Genrated",$s[2],$db);
}
}
}
}
$inipath = php_ini_loaded_file();
date_default_timezone_set("Asia/Calcutta");
$date=date_create();
$data['date'] = date_format($date,"Y-m-d H:i:s");
// price history
if(isset($data['s_price'])){
$temphistory[] = array('date'=> $data['date'],
's_price'=> $data['s_price'],
'e_price'=> (isset($data['e_price']) && $data['e_price']>0?$data['e_price']:0));
if(isset($_POST['id']) && $db->find($_POST['table'], ' id='.$_POST['id'].' AND price_history !="" AND s_price != '.$_POST['s_price'])){
$price = $db->query(' SELECT price_history FROM '.$_POST['table'].' WHERE id='.$_POST['id']);
if($price[0] == 'success' && !empty($price[1])){
$history = json_decode($price[1][0]['price_history']);
foreach($history as $k=>$v){
$history_price[$k]=$v;
}
array_push($history_price,$temphistory[0]);
$data['price_history'] = json_encode($history_price);
}
}
if(isset($_POST['id']) && $db->find($_POST['table'], ' id='.$_POST['id'].' AND price_history = "" ')){
$data['price_history'] = json_encode($temphistory);
}
}
// Password genration
if(isset($_POST['password']) && $_POST['password'] != ""){
$data['password'] = hash('sha512',hash('sha512',$_POST['password']).$_POST['email']);
}
// insert Update
if(isset($_POST['id'])){
$res = $db->update($_POST['table'],$data," id=".$_POST['id']);
$res['id'] = $_POST['id'];
}else{
$data['id'] = ($db->max($_POST['table']) == NULL? 1 : (int)$db->max($_POST['table']) + 1);
if(isset($data['s_price'])){
$data['price_history'] = json_encode($temphistory);
}
$res = $db->insert($_POST['table'],$data);
$res['id'] = $data['id'];
}
if($res[0] == 'error'){
errorlog($_POST['page'],$res[1],$res[2],$db);
}
echo json_encode($res);
}
?>