Framework guides
PHP
Use Quat with the AWS SDK for PHP.
Install
composer require aws/aws-sdk-php vlucas/phpdotenv
Environment
S3_ENDPOINT=https://storage.example.local
S3_ACCESS_KEY=your-access-key
S3_SECRET_KEY=your-secret-key
S3_REGION=us-east-1
S3_BUCKET=my-bucket
S3_USE_PATH_STYLE_ENDPOINT=true
Client
<?php
require __DIR__ . "/vendor/autoload.php";
use Aws\S3\S3Client;
use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->safeLoad();
$s3 = new S3Client([
"version" => "latest",
"region" => $_ENV["S3_REGION"] ?? "us-east-1",
"endpoint" => $_ENV["S3_ENDPOINT"],
"use_path_style_endpoint" => ($_ENV["S3_USE_PATH_STYLE_ENDPOINT"] ?? "true") !== "false",
"credentials" => [
"key" => $_ENV["S3_ACCESS_KEY"],
"secret" => $_ENV["S3_SECRET_KEY"],
],
]);
$bucket = $_ENV["S3_BUCKET"];
Upload Object
<?php
require __DIR__ . "/s3.php";
try {
$s3->putObject([
"Bucket" => $bucket,
"Key" => "reports/monthly.pdf",
"SourceFile" => __DIR__ . "/monthly.pdf",
"ContentType" => "application/pdf",
]);
echo "Uploaded reports/monthly.pdf\n";
} catch (Throwable $e) {
fwrite(STDERR, "Upload failed: {$e->getMessage()}\n");
}
Download Object
<?php
require __DIR__ . "/s3.php";
try {
$s3->getObject([
"Bucket" => $bucket,
"Key" => "reports/monthly.pdf",
"SaveAs" => __DIR__ . "/downloaded-monthly.pdf",
]);
} catch (Throwable $e) {
fwrite(STDERR, "Download failed: {$e->getMessage()}\n");
}
List Objects
<?php
require __DIR__ . "/s3.php";
$result = $s3->listObjectsV2([
"Bucket" => $bucket,
"Prefix" => "reports/",
]);
foreach ($result["Contents"] ?? [] as $object) {
echo $object["Key"] . " " . $object["Size"] . PHP_EOL;
}
Delete Object
<?php
require __DIR__ . "/s3.php";
$s3->deleteObject([
"Bucket" => $bucket,
"Key" => "reports/monthly.pdf",
]);
Presigned URL
<?php
require __DIR__ . "/s3.php";
$command = $s3->getCommand("GetObject", [
"Bucket" => $bucket,
"Key" => "reports/monthly.pdf",
]);
$request = $s3->createPresignedRequest($command, "+15 minutes");
echo (string) $request->getUri() . PHP_EOL;
Note: Test SDK-generated presigned URLs with your deployment. The Quat customer app confirms backend-generated download links for console downloads.