Initial commit - mini cms final

This commit is contained in:
Aya Tess tess
2025-11-03 21:53:58 +01:00
parent a366336dc1
commit a01f620ef9
14 changed files with 422 additions and 197 deletions

View File

@@ -4,10 +4,9 @@ if (session_status() === PHP_SESSION_NONE) {
}
require_once __DIR__ . '/vendor/autoload.php';
use Aws\S3\S3Client;
// ✅ Connexion PDO
// ✅ Connexion PDO MySQL UTF-8 universelle
try {
$pdo = new PDO(
'mysql:host=mysql;dbname=forum_database;charset=utf8mb4',
@@ -15,14 +14,15 @@ try {
'mypassword',
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci"
]
);
} catch (PDOException $e) {
die("Erreur de connexion MySQL : " . $e->getMessage());
die("Erreur de connexion MySQL : " . $e->getMessage());
}
// ✅ Client MinIO
// ✅ Configuration du client MinIO (S3-compatible)
$s3Client = new S3Client([
'version' => 'latest',
'region' => 'us-east-1',
@@ -35,3 +35,36 @@ $s3Client = new S3Client([
]);
$bucketName = 'bucketforum';
// ✅ Sassurer que le bucket existe (création auto si absent)
try {
$buckets = $s3Client->listBuckets();
$bucketExists = false;
foreach ($buckets['Buckets'] as $bucket) {
if ($bucket['Name'] === $bucketName) {
$bucketExists = true;
break;
}
}
if (!$bucketExists) {
$s3Client->createBucket(['Bucket' => $bucketName]);
// Rendre le bucket public automatiquement
$policy = json_encode([
'Version' => '2012-10-17',
'Statement' => [[
'Effect' => 'Allow',
'Principal' => '*',
'Action' => ['s3:GetObject'],
'Resource' => "arn:aws:s3:::{$bucketName}/*"
]]
]);
$s3Client->putBucketPolicy([
'Bucket' => $bucketName,
'Policy' => $policy
]);
}
} catch (Exception $e) {
echo "⚠️ Impossible de vérifier/créer le bucket MinIO : " . $e->getMessage();
}
?>