6
votes

I'm just getting started with the AWS S3 SDK for PHP, I've managed to upload a folder of items from my PC to an s3 bucket using PHP, is there any way to specify a folder inside that bucket, for example, instead of uploading image.jpg to imagebucket, it uploads to the folder called images inside 'imagebucket'.

2
Doesn't $s3->create_object($bucket, 'folder/filename', $options) work?lanzz
lanzz, you sir are a god among men.Jamie Taylor
Have a look at the s3cmd tools. Which solves many problems. s3tools.org/s3cmdJeevan Dongre

2 Answers

5
votes

There is no concept of folders in aws s3. Its just for display purpose used by amazon AWS UI.

Actually it stores filename as key & data as value.

if you store 5 files with different folders, they are not going to create 5 folders.

4
votes

From the docs:

public function uploadDirectory($directory, $bucket, $keyPrefix = null, array $options = array())

By specifying $keyPrefix, you can cause the uploaded objects to be placed under a virtual folder in the Amazon S3 bucket. For example, if the $bucket name is my-bucket and the $keyPrefix is 'testing/', then your files will be uploaded to my-bucket under the testing/ virtual folder: https://my-bucket.s3.amazonaws.com/testing/filename.txt

See: http://docs.aws.amazon.com/aws-sdk-php/guide/latest/service-s3.html#uploading-a-directory-to-a-bucket