| Current Path : /home/h/a/p/happyrenas/myreco.online/administration/ |
Linux webd005.cluster105.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 |
| Current File : /home/h/a/p/happyrenas/myreco.online/administration/supprimer_photo_hebergement_multiple.php |
<?php
include("../configuration.php");
include("../includes/fonctions.php");
setlocale(LC_TIME, 'fr_FR.UTF-8');
header('Content-Type: application/json');
$response = [
'success' => false,
'message' => ''
];
// Vérifications
$token = preg_replace('/[^a-f0-9]/', '', $_POST['token'] ?? '');
$photo = trim($_POST['photo'] ?? '');
if (empty($token) || empty($photo)) {
$response['message'] = 'Paramètres manquants.';
echo json_encode($response);
exit;
}
// Sécurité minimum sur le chemin relatif
if (!preg_match('#^[A-Z0-9]{2}/[a-zA-Z0-9_\-]+\.(jpg|jpeg)$#', $photo)) {
$response['message'] = 'Photo invalide.';
echo json_encode($response);
exit;
}
// Vérifier hébergement
$heb = $db->get_row("SELECT photos_local_json FROM heb WHERE token = '" . $db->escape($token) . "'");
if (!$heb) {
$response['message'] = 'Hébergement introuvable.';
echo json_encode($response);
exit;
}
// JSON existant
$photos_json = json_decode($heb->photos_local_json ?? '[]', true);
$photos_json = is_array($photos_json) ? $photos_json : [];
if (!in_array($photo, $photos_json, true)) {
$response['message'] = 'Photo non trouvée dans la fiche.';
echo json_encode($response);
exit;
}
// Suppression du fichier
$absolute_path = DOSSIER_RACINE . '/upload/hebergement_multiple/' . $photo;
if (file_exists($absolute_path)) {
unlink($absolute_path);
}
// Suppression dans le JSON
$nouvelles_photos = [];
foreach ($photos_json as $photo_json) {
if ($photo_json !== $photo) {
$nouvelles_photos[] = $photo_json;
}
}
// Mise à jour BDD
$db->query("
UPDATE heb
SET photos_local_json = '" . $db->escape(json_encode($nouvelles_photos, JSON_UNESCAPED_UNICODE)) . "'
WHERE token = '" . $db->escape($token) . "'
");
$response['success'] = true;
$response['message'] = 'Photo supprimée avec succès.';
echo json_encode($response);
exit;
?>