yudhaez0212

Untitled

Oct 27th, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. <?php
  2.  
  3. use Aws\S3\S3Client;
  4. use League\Flysystem\AwsS3v3\AwsS3Adapter;
  5. use League\Flysystem\Filesystem;
  6.  
  7. try {
  8. // Wasabi Config
  9. $config = [
  10. "bucket" => "newbuckettesting",
  11. "region" => "us-west-1",
  12. "key" => "AIQLZOLUM4K3J3N89A8Q",
  13. "secret" => "62dVd5cIlziZbJd6IlZH0fE599eFefaT92lJbDyr",
  14. "root" => "/"
  15. ];
  16.  
  17. // Setup Upload
  18. if (isset($_FILES['gambar'])) {
  19. $file_name = $_FILES['gambar']['name'];
  20. $temp_file_location = $_FILES['gambar']['tmp_name'];
  21.  
  22. $s3_conf = [
  23. 'endpoint' => "https://" . $config['bucket'] . ".s3." . $config['region'] . ".wasabisys.com/",
  24. 'bucket_endpoint' => true,
  25. 'credentials' => [
  26. 'key' => $config['key'],
  27. 'secret' => $config['secret'],
  28. ],
  29. 'region' => $config['region'],
  30. 'version' => 'latest',
  31. ];
  32. $s3 = new Aws\S3\S3Client($s3_conf);
  33.  
  34. $result = $s3->putObject([
  35. 'Bucket' => 'storageserver001',
  36. 'Key' => time().'-'.uniqid(), // Nama File
  37. 'SourceFile' => $temp_file_location,
  38. 'ContentType' => $_FILES['gambar']['type'],
  39. 'ACL' => 'public-read'
  40. ]);
  41. $response = $result["@metadata"];
  42.  
  43. if ($response['statusCode'] == 200) {
  44. // Success
  45. $image = $response['effectiveUri']; // https://google.com/image.jpg
  46. } else {
  47. // Gagal
  48. $image = '';
  49. }
  50. }
  51. } catch (\Throwable $th) {}
Add Comment
Please, Sign In to add comment