Skip to content

Instantly share code, notes, and snippets.

@emersonbroga
Created October 26, 2012 21:10
Show Gist options
  • Save emersonbroga/3961552 to your computer and use it in GitHub Desktop.
Save emersonbroga/3961552 to your computer and use it in GitHub Desktop.
Amazon S3 Zend Example
echo '<pre style="background-color: #FFF; color:#000">';
$s3Key = '';
$s3Sectret = '';
$imagePath = UPLOAD_PATH. DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR;
$fileName = 'barcode_2012090000110.jpg';
$bucketName = $_SERVER['HTTP_HOST'];
$objectString = $bucketName.'/'.$fileName;
$s3 = new Zend_Service_Amazon_S3($s3Key, $s3Sectret);
$list = $s3->getBuckets();
foreach($list as $bucket) {
echo "I have bucket $bucket<br/>";
}
$s3->createBucket($bucketName);
$put = $s3->putFile($imagePath . $fileName, $objectString,
array(Zend_Service_Amazon_S3::S3_ACL_HEADER =>
Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ));
echo 'http://s3.amazonaws.com/'.$objectString;
echo '<br/>';
die('Upload complete');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment