Reputation: 98
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
Upvotes: 0
Views: 33
Reputation: 5056
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'];
Upvotes: 1