How to create folder under Amazon S3 bucket through PHP SDK?

100calorie picture 100calorie · Sep 6, 2012 · Viewed 25.3k times · Source

I am developing an iPhone app to allow user upload photo and share. I want to use S3 to store uploaded images as well as processed images (foe example, thumbnail, reduced size image). I've installed AWS PHP SDK on my EC2 instance, my questions are: 1) Should photos uploaded from iPhone app go to a EC2 directory first, then copied over to S3 bucket, or it should directly uploaded to S3? 2) How can I create different folders under the S3 bucket through PHP SDK and how to read the files from the folder?

Thanks in advance!

Answer

Manoj Prajapat picture Manoj Prajapat · Nov 20, 2014

Yes , it is possible to create new folder using s3 sdk.

try bellow code

<?php

 /* abc is the folder name */

 $s3->putObject(array( 
                   'Bucket' => $bucket,
                   'Key'    => "abc/",
                   'Body'   => "",
                   'ACL'    => 'public-read'
                  ));