PHP code example of szhorvath / flysystem-aws-s3-plus

1. Go to this page and download the library: Download szhorvath/flysystem-aws-s3-plus library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

szhorvath / flysystem-aws-s3-plus example snippets




return [
    ...
    'disks' => [
    ...
        's3' => [
            'driver' => 's3-plus',
            ...
        ],
      ],
    ...

Storage::disk('s3')->versions("path/to/file.text");

Illuminate\Support\Collection {
 [
    [
      "id" => "9a18981b-fa18-4793-b406-4deb75744865",
      "hash" => "d93328ed2d2032d8bb6d8c1b49cfc807",
      "key" => "test/text.txt",
      "type" => "file",
      "latest" => true,
      "updatedAt" => Carbon\CarbonImmutable,
      "size" => 14,
    ],
    [
      "id" => "b1baa201-6a3e-4d75-8d36-38895202d8ff",
      "hash" => "",
      "key" => "test/text.txt",
      "type" => "deleteMarker",
      "latest" => false,
      "updatedAt" => Carbon\CarbonImmutable,
      "size" => 0,
    ],
    [
      "id" => "c22753cc-dfb2-4120-992c-ae81effef752",
      "hash" => "9310ca6aea85baa1adb30292d379b274",
      "key" => "test/text.txt",
      "type" => "file",
      "latest" => false,
      "updatedAt" => Carbon\CarbonImmutable,
      "size" => 12,
    ],
  ]
}

Storage::disk('s3')->temporaryUrl(
    path: 'path/to/file.txt',
    expiration: Carbon::now()->addMinutes(1),
    versionId: 'ca3dd4a6-9a92-4368-8ce2-a5df45c63f43'
);

http://s3/bucket/path/to/file.txt?versionId=ca3dd4a6-9a92-4368-8ce2-a5df45c63f43&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=sail%2F20231114%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20231114T170430Z&X-Amz-SignedHeaders=host&X-Amz-Expires=60&X-Amz-Signature=f59d8e667cee7ac9ed5bc1fcfcd4cd02dd742fb9e4dd3f034186ec22dd699647

Storage::disk('s3')->get(
    path: 'path/to/file.txt',
    versionId: 'b51e44fe-d47e-43dd-be6e-d07a4dd823d4'
);

//Multiple paths as arguments
Storage::disk('s3')->delete('path/to/file1.txt', 'path/to/file2.txt', ...);

// Multiple paths as array
Storage::disk('s3')->delete(['path/to/file1.txt', 'path/to/file2.txt', ...]);

// Delete specific version(s) permanently
Storage::disk('s3')->delete([
    'f8ffee13-9a0f-4031-85e7-f92f253ec42e' => 'path/to/file1.txt',  // versionId => path
    'b51e44fe-d47e-43dd-be6e-d07a4dd823d4' => 'path/to/file2.txt',
    ...
]);

// Deleting the Delete marker
Storage::disk('s3')->delete(['f8ffee13-9a0f-4031-85e7-f92f253ec42e' => 'path/to/file1.txt']);

// Copy a previous version of the object into the same bucket.
Storage::disk('s3')->restore('path/to/file1.txt', 'f8ffee13-9a0f-4031-85e7-f92f253ec42e');