Auto commit: 2025-12-18T01:59:13.858Z
This commit is contained in:
parent
7dedde4564
commit
f06143ee16
BIN
assets/images/uploads/thumbnail_694350f6c1cc1.jpg
Normal file
BIN
assets/images/uploads/thumbnail_694350f6c1cc1.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 74 KiB |
@ -12,12 +12,14 @@ class ImageProcessor {
|
||||
*/
|
||||
public static function processAndSaveImage(array $file) {
|
||||
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
|
||||
}
|
||||
|
||||
// Validate file type
|
||||
$allowedTypes = ['image/jpeg', 'image/png', 'image/gif'];
|
||||
if (!in_array($file['type'], $allowedTypes)) {
|
||||
error_log("ImageProcessor: Invalid file type uploaded: " . $file['type']);
|
||||
return false; // Invalid file type
|
||||
}
|
||||
|
||||
@ -33,11 +35,13 @@ class ImageProcessor {
|
||||
|
||||
// Move the uploaded file
|
||||
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
|
||||
}
|
||||
|
||||
// Resize image
|
||||
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
|
||||
unlink($targetPath);
|
||||
return false;
|
||||
@ -75,6 +79,7 @@ class ImageProcessor {
|
||||
$image = imagecreatefromgif($imagePath);
|
||||
break;
|
||||
default:
|
||||
error_log("ImageProcessor: Unsupported image type for resizing: " . $mimeType);
|
||||
return false; // Unsupported image type for resizing
|
||||
}
|
||||
|
||||
|
||||
13
submit.php
13
submit.php
@ -1,8 +1,14 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
session_start();
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
require_once __DIR__ . '/includes/ImageProcessor.php';
|
||||
|
||||
error_log("submit.php: Script started.");
|
||||
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
@ -23,6 +29,7 @@ if (!empty($categories)) {
|
||||
}
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
error_log("submit.php: POST request received.");
|
||||
$title = trim($_POST['title'] ?? '');
|
||||
$url = trim($_POST['url'] ?? '');
|
||||
$description = trim($_POST['description'] ?? '');
|
||||
@ -41,20 +48,26 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$thumbnail_url = null;
|
||||
|
||||
if (isset($_FILES['thumbnail']) && $_FILES['thumbnail']['error'] === UPLOAD_ERR_OK) {
|
||||
error_log("submit.php: Image upload detected. Processing image...");
|
||||
$uploadedImagePath = ImageProcessor::processAndSaveImage($_FILES['thumbnail']);
|
||||
if ($uploadedImagePath) {
|
||||
$thumbnail_url = $uploadedImagePath;
|
||||
error_log("submit.php: Image processed successfully. Path: " . $uploadedImagePath);
|
||||
} else {
|
||||
$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 {
|
||||
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->execute([$_SESSION['user_id'], $subcategory_id, $title, $url, $description, $thumbnail_url, $status]);
|
||||
$success = true;
|
||||
error_log("submit.php: Database insertion successful.");
|
||||
} catch (PDOException $e) {
|
||||
$errors[] = "Database error: " . $e->getMessage();
|
||||
error_log("submit.php: Database error: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user