Skip to content

Instantly share code, notes, and snippets.

@komputronika
Created June 3, 2024 04:35
Show Gist options
  • Save komputronika/7783be7b64775276ffaa6c6589dfb2bc to your computer and use it in GitHub Desktop.
Save komputronika/7783be7b64775276ffaa6c6589dfb2bc to your computer and use it in GitHub Desktop.
Upload file to S3 server (Biznet)
<?php
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
$temp_file ="mydoc.pdf";
$client = new S3Client([
"version" => "latest",
"region" => getenv("BIZ_ACCESS_REGION"),
"endpoint" => "https://" . getenv("BIZ_ENDPOINT"),
"credentials" => [
"key" => getenv("BIZ_ACCESS_KEY_ID"),
"secret" => getenv("BIZ_ACCESS_KEY_SECRET"),
],
]);
try {
$result = $client->putObject(
[
"Bucket" => getenv("BIZ_BUCKET_NAME"),
"Key" => $folder . "/" . $nama_file,
// <string || resource || Psr\Http\Message\StreamInterface>
"Body" => fopen($temp_file, "r"),
// 'private|public-read|public-read-write|authenticated-read|aws-exec-read|bucket-owner-read|bucket-owner-full-control'
"ACL" => "private",
]);
}
catch (S3Exception $e)
{
echo "Upload failed";
die();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment