49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
|
<?php
|
||
|
|
||
|
require_once("../vendor/autoload.php");
|
||
|
// Load environment variables
|
||
|
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . "/..");
|
||
|
$dotenv->load();
|
||
|
$env = array_merge($_ENV, $_SERVER);
|
||
|
ksort($env);
|
||
|
|
||
|
/** @var Aws\S3\S3ClientInterface $client */
|
||
|
$client = new Aws\S3\S3Client([
|
||
|
'region' => 'ti',
|
||
|
'version' => 'latest',
|
||
|
'endpoint' => $env['S3_ENDPOINT'],
|
||
|
'use_path_style_endpoint' => true,
|
||
|
'credentials' => [
|
||
|
'key' => $env['S3_KEY'],
|
||
|
'secret' => $env['S3_SECRET'],
|
||
|
],
|
||
|
]);
|
||
|
|
||
|
// The internal adapter
|
||
|
$adapter = new League\Flysystem\AwsS3V3\AwsS3V3Adapter(
|
||
|
// S3Client
|
||
|
$client,
|
||
|
// Bucket name
|
||
|
$env['S3_BUCKET']
|
||
|
);
|
||
|
|
||
|
// The FilesystemOperator
|
||
|
$filesystem = new League\Flysystem\Filesystem($adapter);
|
||
|
|
||
|
if($env['REQUEST_URI'] == '/') {
|
||
|
foreach($filesystem->listContents("/") as $file) {
|
||
|
echo "<a href=\"{$file['path']}\">{$file['path']}</a><br>";
|
||
|
}
|
||
|
}else {
|
||
|
if ($filesystem->fileExists($env['REQUEST_URI'])) {
|
||
|
// Read file using a stream and output it as a stream
|
||
|
$stream = $filesystem->readStream($env['REQUEST_URI']);
|
||
|
header('Content-Type: ' . $filesystem->mimeType($env['REQUEST_URI']));
|
||
|
fpassthru($stream);
|
||
|
exit;
|
||
|
} else {
|
||
|
header("HTTP/1.0 404 Not Found");
|
||
|
echo "File not found";
|
||
|
}
|
||
|
}
|