Файловый менеджер - Редактировать - /home/skymarketplace/public_html/controllers/HeroImageController.php
Назад
<?php namespace App\Controllers; use App\core\Database; use App\models\HeroModel; use PDO; class HeroImageController { private HeroModel $model; private string $uploadDir = __DIR__ . '../uploads/'; public function __construct(Database $database) { $this->model = new HeroModel($database->getConnection()); } public function uploadHeroImage(array $files): void { if (!isset($files['hero_image'])) { $this->jsonResponse(false, 'No image uploaded.'); return; } $image = $files['hero_image']; $imageName = time() . '_' . basename($image['name']); $targetPath = $this->uploadDir . $imageName; if (!move_uploaded_file($image['tmp_name'], $targetPath)) { $this->jsonResponse(false, 'Image upload failed.'); return; } if ($this->model->insertHeroImage($imageName)) { $this->jsonResponse(true, 'Hero image uploaded successfully.'); } else { $this->jsonResponse(false, 'Database error.'); } } public function deleteHeroImage(array $data): void { $id = $data['delete_hero_id'] ?? null; $image = $data['delete_hero_image'] ?? null; if (!$id || !$image) { $this->jsonResponse(false, 'Missing data for deletion.'); return; } $filePath = $this->uploadDir . $image; if (file_exists($filePath)) { unlink($filePath); } if ($this->model->deleteHeroImage((int)$id)) { $this->jsonResponse(true, 'Hero image deleted successfully.'); } else { $this->jsonResponse(false, 'Database error.'); } } private function jsonResponse(bool $success, string $message): void { echo json_encode([ 'status' => $success ? 'success' : 'error', 'message' => $message ]); } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.31 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка