970_90

Friday, 27 May 2016

Upload Image from URL to S3 in Zend Framework

Upload Image from URL to S3 in Zend Framework


$imageURL = 'https://2.bp.blogspot.com/-AzIU8fSC-a8/V0f9UROmaJI/AAAAAAAAB5w/nu2dxJ8LJgQpRkTGjhsCLtmFbbt0XpT_ACLcB/s1600/Upload%2Bimage%2Bfrom%2BURL%2Bto%2BS3%2Bin%2BZend%2BFramework.png';
$extension = 'png';

$myAwsKey = 'AKIAP3APTHAC2DQLGJA'; //S3 AWS Key
$myAwsSecretKey = 'YJiKlVFERFuF/sadfzgS2jgj6z/Qhjkhsh'; //S3 Secret Key
$s3Media = 's3mediafolder'; //S3 Folder path

$s3 = new Zend_Service_Amazon_S3($myAwsKey, $myAwsSecretKey);
$uploadTo = 'clientProfileImages/thumb/205_test_push.png';

try {
    $s3->putFile($imageURL, "$s3Media/$uploadTo", array(
        Zend_Service_Amazon_S3::S3_ACL_HEADER => Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ,
        'x-amz-storage-class' => 'REDUCED_REDUNDANCY',
        'ContentType' => $extension
    ));
} catch (Exception $e) {
    echo $e->getMessage();
    die;
}
echo 'Image Uploaded Successfully in S3';

No comments:

Post a Comment