<?php


require 'external/aws/aws-autoloader.php';
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;



$bucket = 'quiklrnexam';
$keyName = 's3.php';
$filePath = 's3.php';

try {
   ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
    // Create S3 client using IAM Role (no keys)
    $s3 = new S3Client([
        'region'  => 'ap-south-1', // change region
        'version' => 'latest'
    ]);
   

    $result = $s3->putObject([
        'Bucket'     => $bucket,
        'Key'        => $keyName,
        'SourceFile' => $filePath,
        'ACL'        => 'private'
    ]);

    echo "File uploaded successfully using IAM Role. URL: " . $result['ObjectURL'] . "\n";

} catch (S3Exception $e) {
    echo "Error: " . $e->getMessage();
}



?>