Image Upload On Amazon S3 In Yii

Hi,

I am working on yii framework.

i have facing issue to upload images or files on amazon s3. i am new in yii.

my cms have already image upload or file upload on ec2 instance. then i want to change this functionality and switch store image on ec2 to s3.

i have try s3upload and es3, but i am not able to configure it properly.

then i have try s3assetmanager it’s give error - configure you cache.

Please help !!!

Thanks!!!

Shachish Sneh

Please refer these two wikis:

  1. Php image upload: by Kiran Sharma

  2. Jquery image upload: by Asgaroth

Hope you may find what you want. If not finding useful, discuss your code in the forum, so that you may get some help

this should help you :)

You can "import" the aws sdk in your main config file then just create the class

From the link ( http://blogs.aws.amazon.com/php/post/Tx9BDFNDYYU4VF/Transferring-Files-To-and-From-Amazon-S3 ):

The typical usage of the PutObject operation in the PHP SDK looks like the following:

use Aws\Common\Aws;

$aws = Aws::factory(’/path/to/your/config.php’);

$s3 = $aws->get(‘S3’);

$s3->putObject(array(

'Bucket' => 'your-bucket-name',


'Key'    => 'your-object-key',


'Body'   => 'your-data'

));

The Body parameter can be a string of data, a file resource, or a Guzzle EntityBody object. To use a file resource, you could make a simple change to the previous code sample.

$s3->putObject(array(

'Bucket' => 'your-bucket-name',


'Key'    => 'your-object-key',


'Body'   => fopen('/path/to/your/file.ext', 'r')

));

The SDK also provides a shortcut for uploading directly from a file using the SourceFile parameter, instead of the Body parameter.

$s3->putObject(array(

'Bucket'     => 'your-bucket-name',


'Key'        => 'your-object-key',


'SourceFile' => '/path/to/your/file.ext'

));

When downloading an object via the GetObject operation, you can use the SaveAs parameter as a shortcut to save the object directly to a file.

$s3->getObject(array(

'Bucket' => 'your-bucket-name',


'Key'    => 'your-object-key',


'SaveAs' => '/path/to/store/your/downloaded/file.ext'

));

The SourceFile and SaveAs parameters allow you to use the SDK to directly upload files to and download files from S3 very easily.

You can see more examples of how to use these parameters and perform other S3 operations in our user guide page for Amazon S3. Be sure to check out some of our other helpful S3 features, like our MultipartUpload helper and our S3 Stream Wrapper, which allows you to work with objects in S3 using PHP’s native file functions.