0

I have used below code

//include the S3 class if (!class_exists('S3'))require_once('S3.php'); //AWS access info if (!defined('awsAccessKey')) define('awsAccessKey', '****************'); if (!defined('awsSecretKey')) define('awsSecretKey', '**************************'); //instantiate the class $s3 = new S3(awsAccessKey, awsSecretKey); $s3->putBucket($bucket, S3::ACL_PUBLIC_READ); 

in this where we put Folder Name

2
  • any errors????? Commented Dec 8, 2017 at 7:28
  • use putObjectFile Commented Dec 8, 2017 at 7:29

1 Answer 1

1

In S3 doesn't exist the concept of folder. What you see as folder in S3 console is just an illusion of folder.

Since each object accept / in the key, you can simulate a folder hierarchy (i.e: images/myphoto.jpg) but the filesystem is still flat.

S3 console simulate for you the folder hierarchy, but this notion is file-related, so you can't use putBucket, but putObject with a proper key:

From AWS Doc:

use Aws\S3\S3Client; $bucket = '*** Your Bucket Name ***'; $keyname = 'images/photo.jpg'; // $filepath should be absolute path to a file on disk $filepath = '*** Your File Path ***'; // Instantiate the client. $s3 = S3Client::factory(); // Upload a file. $result = $s3->putObject(array( 'Bucket' => $bucket, 'Key' => $keyname, 'SourceFile' => $filepath, 'ContentType' => 'text/plain', 'ACL' => 'public-read', 'StorageClass' => 'REDUCED_REDUNDANCY', 'Metadata' => array( 'param1' => 'value 1', 'param2' => 'value 2' ) )); echo $result['ObjectURL']; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.