Blog system enhancements: fix publish/unpublish permissions, add action buttons to blog listings, update gallery to show only published blog images, improve blog card layout and description truncation
This commit is contained in:
40
src/processors/blog/upload_blog_image.php
Normal file
40
src/processors/blog/upload_blog_image.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
$rootPath = dirname(dirname(dirname(__DIR__)));
|
||||
require_once($rootPath . "/src/config/env.php");
|
||||
require_once($rootPath . "/src/config/connection.php");
|
||||
require_once($rootPath . "/src/config/functions.php");
|
||||
session_start();
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if (!isset($_FILES['file'])) {
|
||||
echo json_encode(['error' => 'No file uploaded']);
|
||||
http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Get blog_id from query parameter
|
||||
$blog_id = isset($_GET['blog_id']) ? intval($_GET['blog_id']) : null;
|
||||
if (!$blog_id) {
|
||||
echo json_encode(['error' => 'Blog ID required']);
|
||||
http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
$targetDir = $rootPath . "/uploads/blogs/" . $blog_id . "/";
|
||||
if (!file_exists($targetDir)) {
|
||||
mkdir($targetDir, 0777, true);
|
||||
}
|
||||
|
||||
$tmp = $_FILES['file']['tmp_name'];
|
||||
$name = basename($_FILES['file']['name']);
|
||||
$targetFile = $targetDir . uniqid() . "-" . $name;
|
||||
|
||||
if (move_uploaded_file($tmp, $targetFile)) {
|
||||
// Return a relative path for the image
|
||||
$relativePath = "/uploads/blogs/" . $blog_id . "/" . basename($targetFile);
|
||||
echo json_encode(['location' => $relativePath]);
|
||||
} else {
|
||||
echo json_encode(['error' => 'Failed to move uploaded file']);
|
||||
http_response_code(500);
|
||||
}
|
||||
Reference in New Issue
Block a user