File manager - Edit - /home/autoph/public_html/connectv1/api/upload/upload_image_ltms.php
Back
<?php include_once("../../cfg/db.php"); // Function to check if a variable is not empty function isNotEmpty($data) { return preg_match('/\S/', $data); } // Function to compress image function compressImage($source, $destination, $quality) { // Get image info $imgInfo = getimagesize($source); $mime = $imgInfo['mime']; // Create a new image from file switch($mime) { case 'image/jpeg': $image = imagecreatefromjpeg($source); break; case 'image/png': $image = imagecreatefrompng($source); break; case 'image/gif': $image = imagecreatefromgif($source); break; default: $image = imagecreatefromjpeg($source); } // Save image imagejpeg($image, $destination, $quality); imagedestroy($image); // Free up memory } // Handle file deletion if (isset($_REQUEST["request"]) && $_REQUEST["request"] === 'delete') { $file_name = $_REQUEST["name"]; $location = "../../dist/img/customer/ltms/" . $file_name; if (file_exists($location)) { unlink($location); } exit; } // Handle file upload $return_arr = array(); if (!empty($_FILES)) { // Debugging to ensure files are received correctly // echo '<pre>'; print_r($_FILES); echo '</pre>'; exit; $filename = $_FILES['file']['name']; $file_tmp_name = $_FILES['file']['tmp_name']; $file_size = $_FILES['file']['size']; $file_error = $_FILES['file']['error']; if ($file_error === UPLOAD_ERR_OK) { $maxsize = 9097152; $minsize = 300000; if ($file_size >= $maxsize || $file_size == 0) { $return_arr["status"] = 0; $return_arr["message"] = "Image file too large. Image must be less than " . round(($maxsize / 1000000), 0) . " megabytes."; echo json_encode($return_arr); return; } $quality = $file_size >= $minsize ? ($file_size >= $maxsize / 2 ? 30 : 60) : 60; $valid_ext = array('png', 'jpeg', 'jpg'); $file_extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); if (in_array($file_extension, $valid_ext)) { $location = "../../dist/img/customer/ltms/" . $filename; compressImage($file_tmp_name, $location, $quality); try { $db->transBegin(); $customerID = $_REQUEST['cuid']; $dealer_id = $_REQUEST['did']; $created_at = date('Y-m-d h:i:s'); $created_by = $_SESSION['user']['id']; $qry = $db->connect()->query("INSERT INTO `customer_ltms` (`customer_id`, `dealer_id`, `file`, `created_by`, `created_at`) VALUES ('$customerID', '$dealer_id', '$filename', '$created_by', '$created_at')"); if (!$qry) { throw new Exception("Error executing query."); } $db->transCommit(); } catch (Exception $e) { $db->transRollback(); error_log("Exception: " . $e->getMessage()); $return_arr["status"] = 0; $return_arr["message"] = "Error: " . $e->getMessage(); echo json_encode($return_arr); exit; } } else { $return_arr["status"] = 0; $return_arr["message"] = "Invalid file type."; echo json_encode($return_arr); return; } } else { $return_arr["status"] = 0; $return_arr["message"] = "Error with file upload."; echo json_encode($return_arr); return; } $return_arr["status"] = 1; $return_arr["message"] = "Image uploaded successfully."; echo json_encode($return_arr); } else { $return_arr["status"] = 0; $return_arr["message"] = "No files uploaded."; // echo json_encode($return_arr); } if (isset($_REQUEST['apiKey']) && $_REQUEST['apiKey'] === '1164288154587287' ) { if(isset($_REQUEST['cuid'])) { $customer_id = $_REQUEST['cuid']; $file_data = $db->connect()->query("SELECT * FROM customer_ltms WHERE customer_id = '$customer_id' AND is_active=1"); $json_arr['vehicle_image'] = '<div class="col-12 text-center mt-3" id="grid-page-footer"> <div class="card-footer"> <nav aria-label="Contacts Page Navigation"> <ul class="pagination justify-content-center m-0" id="customer-owned-vehicle-paging">No Record</ul> </nav> </div> </div>'; if($file_data->num_rows>0) { $json_arr['vehicle_image'] = ""; foreach ($file_data as $ltms) { $json_arr['vehicle_image'] .= ' <div class="col-md-4 col-sm-6 mb-3"> <div class="card"> <div class="thumbnail"> <a href="dist/img/customer/ltms/' . $ltms['file'] . '" data-toggle="lightbox" data-title="' . $ltms['created_at'] . '" data-gallery="gallery"> <img src="dist/img/customer/ltms/' . $ltms['file'] . '" class="img-fluid" alt="" style="height: 250px; width: 100%;" /> </a> </div> <div class="text-center" ' . ((isset($global_action_permissions['2']['4']) && in_array("3", $global_action_permissions['2']['4'])) ? '' : 'hidden') . '> <p style="color:red; cursor:pointer;" onclick="removeImage(' . $ltms['id'] . ')"><u>Remove</u></p> </div> </div> </div>'; } } echo json_encode($json_arr); } else { $return_arr["status"] = 0; $return_arr["message"] = "No customer record found."; echo json_encode($return_arr); } }else if(isset($_REQUEST['apiKey']) && $_REQUEST['apiKey'] === '9434631886897744' ) { $id = $_REQUEST['id']; $file_data2 = $db->connect()->query("SELECT * FROM customer_ltms WHERE id = '$id'"); // var_dump($file_data); if($file_data2->num_rows>0) { foreach($file_data2 as $file) { try { $db->transBegin(); $qry = $db->connect()->query("UPDATE `customer_ltms` SET is_active=0 WHERE id ='$id'"); if (!$qry) { throw new Exception("Error executing query."); } $location = "../../dist/img/customer/ltms/" . $file['file']; if (file_exists($location)) { unlink($location); } $return_arr["status"] = 1; $return_arr["message"] = "File successfully removed."; $db->transCommit(); echo json_encode($return_arr); } catch (Exception $e) { $db->transRollback(); error_log("Exception: " . $e->getMessage()); $return_arr["status"] = 0; $return_arr["message"] = "Error: " . $e->getMessage(); echo json_encode($return_arr); exit; } } } else { $return_arr["status"] = 0; $return_arr["message"] = "file not found."; echo json_encode($return_arr); } } ?>
| ver. 1.4 |
.
| PHP 7.3.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings