AWS PHP SDK S3 实例

一、下载

我的php版本<5.5,所以sdk版本只能使用V2.0

sdk下载地址:https://github.com/aws/aws-sdk-php/releases?after=2.8.7

(

升级php: http://www.linuxidc.com/Linux/2016-12/137890.htm
可能出现的问题: http://blog.csdn.net/weixin_36333654/article/details/52768704

)


二、使用

文档:http://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.S3.S3Client.html

//获取bucket列表

$result = $client->listBuckets();  
foreach($result['Buckets'] as $b) {  
    var_dump($b);  
}



//上传obj

$result = $client->putObject(array(
    'Bucket' => $bucket,
    'Key' => '201711/404.html',
    'SourceFile' => './404.html',
    'Metadata' => array(
        'Foo' => 'abc',
        'Bar' => '123'
    )
));



//copy

$result = $client->copyObject(array(
    'Bucket' => $bucket,
    'CopySource' => urlencode($bucket . '/'.'201711/404.html'),
    'Key' => '201711/606.html'
));



//获取obj列表

$iterator = $client->getIterator('ListObjects', array('Bucket' => $bucket));
foreach ($iterator as $object) {
    //if(strpos($object['Key'], 'log/')!== false){
        /* $client->deleteObject([
            'Bucket' => $bucket,
            'Key'    => $object['Key']
        ]); */
        echo $object['Key'] . "\n";
    //} 
}


你可能感兴趣的:(亚马逊云AWS,php源码)