1. Go to this page and download the library: Download incursus/laravel-s3-tools 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/ */
incursus / laravel-s3-tools example snippets
// Instantiate an Amazon S3 client.
$s3 = new S3Client([
'version' => 'latest',
'region' => 'us-west-2'
]);
// Fetch the latest version of a file
try {
$s3->putObject([
'Bucket' => 'my-bucket',
'Key' => 'myfile.png',
'VersionId' => 'fiWFsPPFwbvlGh37rB9IaZYkO4pzOgWGz'
]);
} catch (Aws\S3\Exception\S3Exception $e) {
echo "There was an error retrieving the file.\n";
}
$versions = Storage::disk('s3-tools')->getObjectVersions('myfile.png');
foreach($versions as $v)
{
echo '<li> Version ID: ' . $v['versionId'];
echo '<li> File Size: ' . $v['fileSize'] . ' bytes';
echo '<li> Is Latest Version?: ' . $v['isLatest']; // Will be true or false (boolean)
echo '<li> Date Modified: ' . $v['dateModified'];
echo '<li> ----------------------------------------------';
}
// Fetch the latest version of the file from S3
$file = Storage::disk('s3-tools')->get('myfile.png');
// Show the image in the browser
return response($file)->header('Content-Type', 'image/png');
// Fetch the image from S3
$versionId = 'fiWFsPPFwbvlGh37rB9IaZYkO4pzOgWGz';
$file = Storage::disk('s3-tools')->getVersion($versionId)->get('myfile.png');
// Show the image in the browser
return response($file)->header('Content-Type', 'image/png');
// Retrieve a specific version of a file
$versionId = 'fiWFsPPFwbvlGh37rB9IaZYkO4pzOgWGz';
$file = Storage::disk('s3-tools')->setOption('VersionId', $versionId)->get('myfile.png');
// Clear out ll of our options
$file = Storage::disk('s3-tools')->clearOptions();
// or alternatively, just clear the 'VersionId' option
//$file = Storage::disk('s3-tools')->clearOption('VersionId');
// Get the latest version of another file ...
$file = Storage::disk('s3-tools')->get('myfile.png');