Skip to content

Instantly share code, notes, and snippets.

@komputronika
Created June 3, 2024 04:23
Show Gist options
  • Save komputronika/f7d917f4f038b95ac2f0651941b51fe2 to your computer and use it in GitHub Desktop.
Save komputronika/f7d917f4f038b95ac2f0651941b51fe2 to your computer and use it in GitHub Desktop.

Revisions

  1. komputronika created this gist Jun 3, 2024.
    33 changes: 33 additions & 0 deletions get_s3_file.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    <?php

    use Aws\S3\S3Client;
    use Aws\S3\Exception\S3Exception;

    $key = "myfolder/myfile.ext";

    $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"),
    ],
    ]);

    $result = $client->getObject([
    "Bucket" => getenv("BIZ_BUCKET_NAME"),
    "Key" => $key,
    ]);

    $body = $result->get("Body");
    $body->rewind();

    // Add http header here, for example:
    // header('Content-Type: application/pdf');
    // header('Content-Disposition: inline; filename="mydoc.pdf"');

    echo $body;

    ?>