aws上傳文件及配置


php.in 最后一頁 配置cacert.pem證書文件,否則解析不了aws存儲桶的路由

curl.cainfo = D:/phpstudy_pro/cacert.pem

引入

use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;

//aws認證

$credentials = new Aws\Credentials\Credentials('key', 'secret');

$S3Client= new Aws\S3\S3Client([
                'version' =>'aws.version',//存儲桶地區
                'region' =>'2006-03-01',//日期
                'credentials' => $credentials
                ]);

//存儲桶列表

$S3Client->listbuckets();

//獲取對象列表

$bucket='';//存儲桶

$S3Client->listObject('bucket'=>'aws.bucket');

//分段上傳文件

$source='../images/111.png';//文件路徑

$photo_name='test.png';//文件上傳名字

$S3Client = new Aws\S3\MultipartUploader($S3Client, $source, [
            'bucket' =>'aws.bucket',
            'key'    => $photo_name,            
            ]);
        try {
            $result = $S3Client->upload();
            return  $result['Key'];
        } catch (MultipartUploadException $e) {
            return $e->getMessage() . "\n";
        }

//預簽名獲取文件路由

$cmd = $S3Client->getCommand('GetObject', [
            'Bucket' =>'aws.bucket',
            'Key' => $key //aws文件健名
        ]);
        $request = $config->createPresignedRequest($cmd, '+20 minutes');
        $presignedUrl = (string)$request->getUri();


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM