Skip to content
Snippets Groups Projects
Commit 2cfb6108 authored by Romain's avatar Romain
Browse files

debug gestion chevaux admin

parent f17d949a
No related branches found
No related tags found
1 merge request!1Merge Request - Développement vers Main (Draft)
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Racine absolue du projet (depuis /var/www/html/...) // Racine absolue du projet (depuis /var/www/html/...)
define('ROOT_PATH', realpath(__DIR__ . '/..')); define('ROOT_PATH', realpath(__DIR__ . '/..'));
define('INCLUDES_PATH', ROOT_PATH . '/includes'); define('INCLUDES_PATH', ROOT_PATH . '/includes');
define('ASSETS_PATH', ROOT_PATH . '/assets');
define('ASSETS_URL', '/assets'); // Pour les liens HTML vers CSS, images, etc. define('ASSETS_URL', '/assets'); // Pour les liens HTML vers CSS, images, etc.
// Informations de connexion à la base de données // Informations de connexion à la base de données
......
...@@ -31,13 +31,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { ...@@ -31,13 +31,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
} }
$new_filename = uniqid() . '.' . $filetype; $new_filename = uniqid() . '.' . $filetype;
$upload_path = '<?= ASSETS_URL ?>/images/' . $new_filename; $upload_path = ROOT_PATH . '/assets/images/' . $new_filename;
if (!move_uploaded_file($_FILES['image']['tmp_name'], $upload_path)) { if (!move_uploaded_file($_FILES['image']['tmp_name'], $upload_path)) {
throw new Exception("Erreur lors du téléchargement de l'image"); throw new Exception("Erreur lors du téléchargement de l'image");
} }
$image_url = '<?= ASSETS_URL ?>/images/' . $new_filename; $image_url = ASSETS_URL . '/images/' . $new_filename;
} }
// Insertion dans la base de données // Insertion dans la base de données
......
...@@ -53,14 +53,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update'])) { ...@@ -53,14 +53,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update'])) {
} }
$new_filename = uniqid() . '.' . $filetype; $new_filename = uniqid() . '.' . $filetype;
$upload_path = $upload_directory . $new_filename; // Définir le chemin du dossier d'upload
$db_image_path = '<?= ASSETS_URL ?>/images/' . $new_filename; $upload_path = ASSETS_PATH . '/images/' . $new_filename;
$db_image_path = ASSETS_URL . '/images/' . $new_filename;
if (move_uploaded_file($_FILES['image']['tmp_name'], $upload_path)) { if (move_uploaded_file($_FILES['image']['tmp_name'], $upload_path)) {
$image_url = $db_image_path; $image_url = $db_image_path;
// Supprimer l'ancienne image si elle existe // Supprimer l'ancienne image si elle existe
$old_image_path = __DIR__ . './../../' . ltrim($_POST['current_image'], './'); $old_image_path = ROOT_PATH . '/' . ltrim($_POST['current_image'], './');
if ($_POST['current_image'] && file_exists($old_image_path)) { if ($_POST['current_image'] && file_exists($old_image_path)) {
unlink($old_image_path); unlink($old_image_path);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment