Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use Aws\S3\S3Client;
- use League\Flysystem\AwsS3v3\AwsS3Adapter;
- use League\Flysystem\Filesystem;
- try {
- // Wasabi Config
- $config = [
- "bucket" => "newbuckettesting",
- "region" => "us-west-1",
- "key" => "AIQLZOLUM4K3J3N89A8Q",
- "secret" => "62dVd5cIlziZbJd6IlZH0fE599eFefaT92lJbDyr",
- "root" => "/"
- ];
- // Setup Upload
- if (isset($_FILES['gambar'])) {
- $file_name = $_FILES['gambar']['name'];
- $temp_file_location = $_FILES['gambar']['tmp_name'];
- $s3_conf = [
- 'endpoint' => "https://" . $config['bucket'] . ".s3." . $config['region'] . ".wasabisys.com/",
- 'bucket_endpoint' => true,
- 'credentials' => [
- 'key' => $config['key'],
- 'secret' => $config['secret'],
- ],
- 'region' => $config['region'],
- 'version' => 'latest',
- ];
- $s3 = new Aws\S3\S3Client($s3_conf);
- $result = $s3->putObject([
- 'Bucket' => 'storageserver001',
- 'Key' => time().'-'.uniqid(), // Nama File
- 'SourceFile' => $temp_file_location,
- 'ContentType' => $_FILES['gambar']['type'],
- 'ACL' => 'public-read'
- ]);
- $response = $result["@metadata"];
- if ($response['statusCode'] == 200) {
- // Success
- $image = $response['effectiveUri']; // https://google.com/image.jpg
- } else {
- // Gagal
- $image = '';
- }
- }
- } catch (\Throwable $th) {}
Add Comment
Please, Sign In to add comment