Auto commit: 2025-12-18T01:59:13.858Z

This commit is contained in:
Flatlogic Bot 2025-12-18 01:59:13 +00:00
parent 7dedde4564
commit f06143ee16
3 changed files with 18 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

View File

@ -12,12 +12,14 @@ class ImageProcessor {
*/ */
public static function processAndSaveImage(array $file) { public static function processAndSaveImage(array $file) {
if (!isset($file['tmp_name']) || $file['error'] !== UPLOAD_ERR_OK) { if (!isset($file['tmp_name']) || $file['error'] !== UPLOAD_ERR_OK) {
error_log("ImageProcessor: No file uploaded or an error occurred. File error code: " . ($file['error'] ?? 'unknown'));
return false; // No file uploaded or an error occurred return false; // No file uploaded or an error occurred
} }
// Validate file type // Validate file type
$allowedTypes = ['image/jpeg', 'image/png', 'image/gif']; $allowedTypes = ['image/jpeg', 'image/png', 'image/gif'];
if (!in_array($file['type'], $allowedTypes)) { if (!in_array($file['type'], $allowedTypes)) {
error_log("ImageProcessor: Invalid file type uploaded: " . $file['type']);
return false; // Invalid file type return false; // Invalid file type
} }
@ -33,11 +35,13 @@ class ImageProcessor {
// Move the uploaded file // Move the uploaded file
if (!move_uploaded_file($file['tmp_name'], $targetPath)) { if (!move_uploaded_file($file['tmp_name'], $targetPath)) {
error_log("ImageProcessor: Failed to move uploaded file from " . $file['tmp_name'] . " to " . $targetPath);
return false; // Failed to move uploaded file return false; // Failed to move uploaded file
} }
// Resize image // Resize image
if (!self::resizeImage($targetPath, $file['type'])) { if (!self::resizeImage($targetPath, $file['type'])) {
error_log("ImageProcessor: Failed to resize image: " . $targetPath);
// If resizing fails, you might want to delete the original uploaded file // If resizing fails, you might want to delete the original uploaded file
unlink($targetPath); unlink($targetPath);
return false; return false;
@ -75,6 +79,7 @@ class ImageProcessor {
$image = imagecreatefromgif($imagePath); $image = imagecreatefromgif($imagePath);
break; break;
default: default:
error_log("ImageProcessor: Unsupported image type for resizing: " . $mimeType);
return false; // Unsupported image type for resizing return false; // Unsupported image type for resizing
} }

View File

@ -1,8 +1,14 @@
<?php <?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start(); session_start();
require_once __DIR__ . '/db/config.php'; require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/includes/ImageProcessor.php'; require_once __DIR__ . '/includes/ImageProcessor.php';
error_log("submit.php: Script started.");
if (!isset($_SESSION['user_id'])) { if (!isset($_SESSION['user_id'])) {
header("Location: login.php"); header("Location: login.php");
exit; exit;
@ -23,6 +29,7 @@ if (!empty($categories)) {
} }
if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($_SERVER["REQUEST_METHOD"] == "POST") {
error_log("submit.php: POST request received.");
$title = trim($_POST['title'] ?? ''); $title = trim($_POST['title'] ?? '');
$url = trim($_POST['url'] ?? ''); $url = trim($_POST['url'] ?? '');
$description = trim($_POST['description'] ?? ''); $description = trim($_POST['description'] ?? '');
@ -41,20 +48,26 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
$thumbnail_url = null; $thumbnail_url = null;
if (isset($_FILES['thumbnail']) && $_FILES['thumbnail']['error'] === UPLOAD_ERR_OK) { if (isset($_FILES['thumbnail']) && $_FILES['thumbnail']['error'] === UPLOAD_ERR_OK) {
error_log("submit.php: Image upload detected. Processing image...");
$uploadedImagePath = ImageProcessor::processAndSaveImage($_FILES['thumbnail']); $uploadedImagePath = ImageProcessor::processAndSaveImage($_FILES['thumbnail']);
if ($uploadedImagePath) { if ($uploadedImagePath) {
$thumbnail_url = $uploadedImagePath; $thumbnail_url = $uploadedImagePath;
error_log("submit.php: Image processed successfully. Path: " . $uploadedImagePath);
} else { } else {
$errors[] = 'Failed to process uploaded image. Please ensure it is a valid image file (JPEG, PNG, GIF).'; $errors[] = 'Failed to process uploaded image. Please ensure it is a valid image file (JPEG, PNG, GIF).';
error_log("submit.php: Failed to process uploaded image.");
} }
} }
try { try {
error_log("submit.php: Attempting database insertion...");
$stmt = $pdo->prepare("INSERT INTO links (user_id, subcategory_id, title, url, description, thumbnail_url, status) VALUES (?, ?, ?, ?, ?, ?, ?)"); $stmt = $pdo->prepare("INSERT INTO links (user_id, subcategory_id, title, url, description, thumbnail_url, status) VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$_SESSION['user_id'], $subcategory_id, $title, $url, $description, $thumbnail_url, $status]); $stmt->execute([$_SESSION['user_id'], $subcategory_id, $title, $url, $description, $thumbnail_url, $status]);
$success = true; $success = true;
error_log("submit.php: Database insertion successful.");
} catch (PDOException $e) { } catch (PDOException $e) {
$errors[] = "Database error: " . $e->getMessage(); $errors[] = "Database error: " . $e->getMessage();
error_log("submit.php: Database error: " . $e->getMessage());
} }
} }
} }