Friday, 27 May 2016

Upload Image from URL to S3 in Zend Framework

Upload Image from URL to S3 in Zend Framework


$imageURL = 'https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidv97qmJwUu4M0TAG5vrIuRLFN1YpSwJnDp6huR_eRyN3OeV2tKg_7hyK9adAH3ex6bAys6LZur073vkHRl3833KjuuoVwlaq3b1XfvqGUBKJo3TZZh54KkqgtAVGv9yQdSLkkCK47L-G2/s1600/Upload+image+from+URL+to+S3+in+Zend+Framework.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';