How to Connect S3 Aws Bucket And Get Image

AWS / April 9, 2022 / by nwebsolution
public static function productImageGet($isbn13)

    {
        $path = getcwd();
        require_once($path.'/application/third_party/s3/vendor/autoload.php');
        $s3Url = "Yoururl";
        $bucket = 'Yourbucketname';
        $credentials = new Aws\Credentials\Credentials('enter your accesskey', 'enteryourscretekey');
        $s3 = new Aws\S3\S3Client([
            'version' => 'latest',
            'region'  => 'eu-usa-1',
            'credentials' => $credentials
        ]);
        if($s3->doesObjectExist($bucket, 'images/'.$isbn13.'.jpg')) 
        {
            return $s3Url.$isbn13.".jpg";
        }
        else 
        {
            return $s3Url."no-product-image.jpg";
            // if($s3->doesObjectExist($bucket, 'images/no-product-image.jpg')) 
            // {
            //     return $s3Url."no-product-image.jpg";
            // }
            // else
            // {
            //     return site_url("assets/uploads/no-product-image.jpg");
            // }
        }
    }
Tags:
1 Comment
  • A WordPress Commenter April 9, 2022

    Hi, this is a comment.
    To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
    Commenter avatars come from Gravatar.

Leave a comment