Created
June 3, 2024 04:35
-
-
Save komputronika/7783be7b64775276ffaa6c6589dfb2bc to your computer and use it in GitHub Desktop.
Upload file to S3 server (Biznet)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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