File manager - Edit - /home/autoph/public_html/ltms-upload/upload11-19-24.php
Back
<?php include_once('conn-db.php'); // 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 } function generateUniqueReference($length) { $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; $reference = ''; for ($i = 0; $i < $length; $i++) { $reference .= $characters[rand(0, strlen($characters) - 1)]; } return $reference; } // Handle file deletion if (isset($_REQUEST["request"]) && $_REQUEST["request"] === 'delete') { $file_name = $_REQUEST["name"]; // $location = "../../dist/img/customer/ltms/" . $file_name; // $location = "uploads/" . $file_name; $location = "../data_consolidation/dist/img/customer/ltms-customer-upload/" . $filename; 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 = "../../data_consolidation/dist/img/customer/ltms-customer-upload/" . $filename; $location = "../data_consolidation/dist/img/customer/ltms-customer-upload/" . $filename; // $location = "uploads/" . $filename; compressImage($file_tmp_name, $location, $quality); try { $pdo->beginTransaction(); $fullname = $_REQUEST['fullname']; $cs_number = $_REQUEST['cs_number']; $created_at = date('Y-m-d h:i:s'); do { $unique_reference = generateUniqueReference(6); $stmtCheck = $pdo->prepare("SELECT COUNT(*) FROM `customer_upload_ltms` WHERE `reference` = :reference"); $stmtCheck->bindParam(':reference', $unique_reference); $stmtCheck->execute(); } while ($stmtCheck->fetchColumn() > 0); $stmt = $pdo->prepare("INSERT INTO `customer_upload_ltms` (`reference`,`fullname`,`cs_number`, `filename`, `directory`, `extension`, `size`, `created_at`) VALUES (:reference, :fullname, :cs_number, :filename, :directory, :extension, :size, :created_at)"); $stmt->bindParam(':fullname', $fullname); $stmt->bindParam(':cs_number', $cs_number); $stmt->bindParam(':filename', $filename); $stmt->bindParam(':directory', $location); // $stmt->bindValue(':directory', 'uploads/'); $stmt->bindParam(':extension', $file_extension); $stmt->bindParam(':size', $file_size); $stmt->bindParam(':created_at', $created_at); $stmt->bindParam(':reference', $unique_reference); $stmt->execute(); $pdo->commit(); $return_arr["status"] = 1; $return_arr["message"] = "Image uploaded and data inserted successfully."; } catch (Exception $e) { // Rollback the transaction if something failed $pdo->rollBack(); error_log("Exception: " . $e->getMessage()); $return_arr["status"] = 0; $return_arr["message"] = "Error: " . $e->getMessage(); } } 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); } ?>
| ver. 1.4 |
.
| PHP 7.3.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings