setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Выход if (isset($_GET['logout'])) { session_destroy(); header("Location: /ui"); exit; } // Авторизация if (isset($_POST['login'])) { $stmt = $db->prepare("SELECT * FROM s3_mounts WHERE dav_user = ?"); $stmt->execute([$_POST['username']]); $user = $stmt->fetch(); if ($user && password_verify($_POST['password'], $user['dav_pass'])) { $_SESSION['ui_user'] = $user; header("Location: /ui"); exit; } else { sleep(2); // Защита от брутфорса $error = "Неверный логин или пароль"; } } // Экран входа if (!isset($_SESSION['ui_user'])) { ?> Вход | S3 Web UI

Вход в хранилище

$error
"; ?>
'latest', 'region' => $mount['s3_region'], 'endpoint' => $mount['s3_endpoint'], 'credentials' => [ 'key' => $mount['s3_key'], 'secret' => $mount['s3_secret'], ], 'use_path_style_endpoint' => true ]); $bucket = $mount['s3_bucket']; $prefix = isset($_GET['path']) ? $_GET['path'] : ''; if ($prefix !== '' && substr($prefix, -1) !== '/') $prefix .= '/'; // --- Обработка действий --- try { if (isset($_FILES['file'])) { $s3->putObject([ 'Bucket' => $bucket, 'Key' => $prefix . $_FILES['file']['name'], 'SourceFile' => $_FILES['file']['tmp_name'] ]); header("Location: /ui?path=" . urlencode($prefix)); exit; } if (isset($_POST['new_folder'])) { $folderName = trim($_POST['new_folder']); if (!empty($folderName)) { $s3->putObject(['Bucket' => $bucket, 'Key' => $prefix . $folderName . '/', 'Body' => '']); } header("Location: /ui?path=" . urlencode($prefix)); exit; } if (isset($_POST['delete_key'])) { $s3->deleteObject(['Bucket' => $bucket, 'Key' => $_POST['delete_key']]); header("Location: /ui?path=" . urlencode($prefix)); exit; } } catch (AwsException $e) { $action_error = "Ошибка S3: " . $e->getMessage(); } // Получение списка файлов $objects = []; $folders = []; try { $result = $s3->listObjectsV2([ 'Bucket' => $bucket, 'Prefix' => $prefix, 'Delimiter' => '/' ]); if (isset($result['CommonPrefixes'])) { foreach ($result['CommonPrefixes'] as $p) $folders[] = $p['Prefix']; } if (isset($result['Contents'])) { foreach ($result['Contents'] as $c) { if ($c['Key'] !== $prefix) $objects[] = $c; } } } catch (AwsException $e) { die("Ошибка подключения к S3: " . $e->getMessage()); } function getPresignedUrl($s3, $bucket, $key) { $cmd = $s3->getCommand('GetObject', ['Bucket' => $bucket, 'Key' => $key]); $request = $s3->createPresignedRequest($cmd, '+2 hours'); return (string) $request->getUri(); } // Хлебные крошки $pathParts = array_filter(explode('/', $prefix)); $breadcrumbsHTML = ""; $accPath = ''; foreach ($pathParts as $part) { $accPath .= $part . '/'; $breadcrumbsHTML .= ""; } // Категории файлов для UI $imgExt = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg']; $vidExt = ['mp4', 'webm', 'ogg', 'mov', 'avi']; $audExt = ['mp3', 'wav', 'ogg', 'flac']; $txtExt = ['txt', 'md', 'json', 'csv', 'log', 'xml', 'php', 'html', 'css', 'js']; ?> S3 Файловый менеджер
$action_error
"; ?>
__toString())); $url = getPresignedUrl($s3, $bucket, $obj['Key']); $ext = strtolower(pathinfo($fileName, PATHINFO_EXTENSION)); // Определяем тип файла для иконок и логики открытия $viewType = 'download'; $icon = 'bi-file-earmark text-secondary'; if (in_array($ext, $imgExt)) { $viewType = 'image'; $icon = 'bi-file-image text-info'; } elseif (in_array($ext, $vidExt)) { $viewType = 'video'; $icon = 'bi-file-play-fill text-primary'; } elseif (in_array($ext, $audExt)) { $viewType = 'audio'; $icon = 'bi-file-music text-success'; } elseif (in_array($ext, $txtExt)) { $viewType = 'text'; $icon = 'bi-file-text text-light'; } ?>
Имя Размер Изменен Действия
- -
Папка пуста