Created
August 22, 2024 11:24
-
-
Save reppair/a5f24000c983c8d985b136a8c7bb3ab0 to your computer and use it in GitHub Desktop.
Download S3 file to local filsystem with PHP
This file contains hidden or 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; | |
| $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