| 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/domains/cdn.urbanpillar.in/public_html/ |
| Current File : /home/u901718425/domains/cdn.urbanpillar.in/public_html/deletePropertyImage.php |
<?php
include_once "conn.php";
$res = [];
if ($_POST) {
// id is only needed for update and identify the record, so we remove it from the array
if(!isset($_POST['id']) && !isset($_POST['path'])){
$res[0] = 'error';
$res[1] = 'plase fill the fileds';
}else{
$pool = new ConnectionPool();
$connection1 = $pool->getConnection();
if ($connection1) {
$pdo = $connection1;
}
try {
// Define the SQL query
if( $_POST['path'] != "uploads/noimage.png" && unlink($_POST['path']) ){
$insertQuery = "DELETE FROM `image` WHERE id = ?";
$insertStmt = $pdo->prepare($insertQuery);
$result = $insertStmt->execute([$_POST['id']]);
}
// You don't need to fetch results for an UPDATE query
work($_POST['updated_by'], $_POST['id'],'Delete Project Image');
$res[0] = 'success';
$res[1] = $result;
} catch (PDOException $e) {
// Handle any connection or query errors
$res[0] = 'error';
$res[1] = $e;
} finally {
// Release the connection back to the pool
$pool->releaseConnection($connection1);
}
}
echo json_encode($res);
}
function convert_img_to_webp($file, $targetDir) {
$sourceFile = pathinfo($file, PATHINFO_FILENAME);
$outputFile = $targetDir . $sourceFile . '.webp';
$image = @imagecreatefromstring(file_get_contents($file));
if ($image !== false) {
imagewebp($image, $outputFile);
imagedestroy($image);
return $outputFile;
}
return false;
}
function uploadImage($file)
{
$filename = $_FILES['image']['name'];
$tempPath = $_FILES['image']['tmp_name'];
$targetDir = 'uploads/' . date('Y/m/d') . '/';
$targetPath = $targetDir .'urbanpillar_'.$_POST['title']."_".rand()."_". basename($filename);
// Create the directory structure if it doesn't exist
if (!is_dir($targetDir)) {
mkdir($targetDir, 0777, true);
}
// Move the file to the specified path
move_uploaded_file($tempPath, $targetPath);
// // Convert to WebP if it's not already
// if (pathinfo($filename, PATHINFO_EXTENSION) != 'webp') {
// $targetPath = convert_img_to_webp($targetPath, $targetDir);
// }
return $targetPath;
}
?>