Skip to content

Instantly share code, notes, and snippets.

@reppair
Created August 22, 2024 11:24
Show Gist options
  • Select an option

  • Save reppair/a5f24000c983c8d985b136a8c7bb3ab0 to your computer and use it in GitHub Desktop.

Select an option

Save reppair/a5f24000c983c8d985b136a8c7bb3ab0 to your computer and use it in GitHub Desktop.
Download S3 file to local filsystem with PHP
<?php
use Aws\S3\S3Client;
$client = S3Client::factory([
'credentials' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY')
],
'region' => env('AWS_DEFAULT_REGION'),
'version' => 'latest'
]);
// Register the stream wrapper from an S3Client object
$client->registerStreamWrapper();
$path = 's3://cdpoolbackups/CD-Pool/2024-08-22-09-16-40.zip';
$remote_fp = fopen($path, "r");
$local_fp = fopen("/home/forge/test.zip", "w");
while ($buf = fread($remote_fp, 1024)) {
fwrite($local_fp, $buf);
}
fclose($remote_fp);
fclose($local_fp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment