PHP code example of nzo / s3-aws-bundle

1. Go to this page and download the library: Download nzo/s3-aws-bundle 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/ */

    

nzo / s3-aws-bundle example snippets


use Nzo\S3AwsBundle\S3\S3AwsHandler;
    
    private $s3AwsHandler;

    public function __construct(S3AwsHandler $s3AwsHandler)
    {
        $this->s3AwsHandler = $s3AwsHandler;
        
        // without autowiring use: $this->get('nzo_s3_aws')
    }

    public function uploadFilesToS3Aws(string $key, string $filePath)
    {
        try {

            // $key: it represent the file name and path in the S3 Bucket. Example: "my_folder/my-image.jpg"
            // $filePath: is the absolute path to the file. Example: "/var/www/my-image.jpg"

            $awsResult = $this->s3AwsHandler->uploadFile($key, $filePath);


            // Public ACL (default 'private')
            $acl = 'public-read';
            $awsResult = $this->s3AwsHandler->uploadFile($key, $filePath, $acl);

        } catch (\Exception $e) {
            // Unable to upload the file to AWS S3
        }
    }
 php
// config/bundles.php

return [
    // ...
    Nzo\S3AwsBundle\NzoS3AwsBundle::class => ['all' => true],
];