false, 'error' => 'Erreur upload: ' . $file['error']]); exit; } if ($file['size'] > $MAX_SIZE) { echo json_encode(['success' => false, 'error' => 'Fichier trop volumineux (max 10 MB)']); exit; } // Déterminer l'extension $originalName = $file['name']; $ext = strtolower(pathinfo($originalName, PATHINFO_EXTENSION)); // Si c'est un collage (blob), détecter le type MIME if (empty($ext) || $ext === 'blob') { $mime = mime_content_type($file['tmp_name']); $mimeMap = [ 'image/png' => 'png', 'image/jpeg' => 'jpg', 'image/gif' => 'gif', 'image/webp' => 'webp', 'image/svg+xml' => 'svg', ]; $ext = $mimeMap[$mime] ?? ''; } if (!in_array($ext, $ALLOWED_EXTENSIONS)) { echo json_encode(['success' => false, 'error' => "Extension non autorisée: $ext"]); exit; } // Nom du fichier : soit le nom custom, soit le nom original, soit un timestamp $customName = isset($_POST['filename']) ? trim($_POST['filename']) : ''; if ($customName) { // Nettoyer le nom $customName = preg_replace('/[^a-zA-Z0-9_\-]/', '-', $customName); $filename = $customName . '.' . $ext; } elseif ($originalName && $originalName !== 'blob' && $originalName !== 'image.png') { $filename = preg_replace('/[^a-zA-Z0-9_\-\.]/', '-', $originalName); } else { $filename = date('Y-m-d_H-i-s') . '.' . $ext; } $targetPath = $targetDir . $filename; // Éviter l'écrasement if (file_exists($targetPath)) { $base = pathinfo($filename, PATHINFO_FILENAME); $filename = $base . '_' . time() . '.' . $ext; $targetPath = $targetDir . $filename; } if (move_uploaded_file($file['tmp_name'], $targetPath)) { $mdPath = "assets/images/$subdir/$filename"; echo json_encode([ 'success' => true, 'filename' => $filename, 'subdir' => $subdir, 'markdown' => "", 'path' => $mdPath, ]); } else { echo json_encode(['success' => false, 'error' => 'Impossible de déplacer le fichier']); } exit; } // Lister les images existantes $existingImages = []; foreach ($SUBDIRS as $sd) { $dir = $UPLOAD_DIR . $sd . '/'; if (is_dir($dir)) { $files = scandir($dir); foreach ($files as $f) { if ($f === '.' || $f === '..') continue; $ext = strtolower(pathinfo($f, PATHINFO_EXTENSION)); if (in_array($ext, $ALLOWED_EXTENSIONS)) { $existingImages[] = [ 'name' => $f, 'subdir' => $sd, 'path' => "assets/images/$sd/$f", 'url' => "docs/assets/images/$sd/$f", 'size' => filesize($dir . $f), ]; } } } } // Image à la racine de images/ $rootDir = $UPLOAD_DIR; if (is_dir($rootDir)) { $files = scandir($rootDir); foreach ($files as $f) { if ($f === '.' || $f === '..' || is_dir($rootDir . $f)) continue; $ext = strtolower(pathinfo($f, PATHINFO_EXTENSION)); if (in_array($ext, $ALLOWED_EXTENSIONS)) { $existingImages[] = [ 'name' => $f, 'subdir' => '(racine)', 'path' => "assets/images/$f", 'url' => "docs/assets/images/$f", 'size' => filesize($rootDir . $f), ]; } } } ?>
Documentation SmartEye — Glissez, cliquez ou collez (Cmd+V) une image
Glissez une image ici ou cliquez pour sélectionner
Cmd+V pour coller depuis le presse-papiers • JPG, PNG, GIF, WebP, SVG • Max 10 MB
Aucune image pour l'instant.