This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once("aws.phar"); | |
use Aws\Common\Aws; | |
use Aws\Common\Enum\Region; | |
use Aws\S3\Enum\CannedAcl; | |
use Aws\S3\Exception\S3Exception; | |
use Guzzle\Http\EntityBody; | |
$access_key = 'Your Access Key'; | |
$secret_key = 'Your Secret Key'; | |
$region = Region::AP_NORTHEAST_1; // Region::AP_NORTHEAST_1 = Tokyo Region | |
$bucket = 's3_bucket_name'; | |
try { | |
// S3 | |
$s3 = Aws::factory(array( | |
'key' => $access_key, | |
'secret' => $secret_key, | |
'region' => $region, | |
))->get('s3'); | |
$info = new FInfo(FILEINFO_MIME_TYPE); | |
// Upload File | |
$filename = 'test.txt'; | |
$filebody = EntityBody::factory(fopen($filename, 'r')); | |
$filetype = $info->file($filename); | |
$response = $s3->putObject(array( | |
'Bucket' => $bucket, | |
'Key' => $filename, | |
'Body' => $filebody, | |
'ContentType' => $filetype, | |
'StorageClass' => 'STANDARD', // STANDARD or REDUCED_REDUNDANCY | |
//'ServerSideEncryption => 'AES256', | |
'ACL' => CannedAcl::PUBLIC_READ, // PUBLIC_READ, PRIVATE_ACCESS… | |
)); | |
var_dump($response); | |
} catch (S3Exception $e) { | |
} |
Region の設定値: PHP 2: Class Aws\Common\Enum\Region | AWS SDK for PHP 2
ACL の設定値: PHP 2: Class Aws\S3\Enum\CannedAcl | AWS SDK for PHP 2
コメントを残す