kiwfy / aws-bucket-php
7.0.0
2023-11-27 11:22 UTC
Requires
- php: ^8.3
- aws/aws-sdk-php: ^3.289
- not-empty/ulid-php-lib: ^7.0
Requires (Dev)
- mockery/mockery: ^1.6
- phpmd/phpmd: ^2.14
- phpunit/phpunit: ^9.6
- squizlabs/php_codesniffer: ^3.7
README
PHP库,用于连接和使用AWS S3桶。
安装
版本 7.0.0 需要 PHP 8.3
版本 6.0.0 需要 PHP 8.2
版本 5.0.0 需要 PHP 8.1
版本 4.0.0 需要 PHP 7.4
版本 3.0.0 需要 PHP 7.3
版本 2.0.0 需要 PHP 7.2
版本 1.0.0 需要 PHP 7.1
推荐的安装方式是通过Composer。
composer require not-empty/aws-bucket-php-lib
使用
上传文件
use AwsBucket\AwsBucket; $config = [ 'credentials' => [ 'key' => '', //you must put your aws iam key here 'secret' => '', //you must put your aws iam secret here ], 'version' => 'latest', 'region' => 'us-east-1', //you must put your bucket region here ]; $awsBucket = new AwsBucket($config); $bucket = 'my-bucket'; //you must put your bucket name here $content = 'this is your file content'; $name = 'sample'; $extension = 'txt'; $putFile = $awsBucket->putFile( $bucket, $content, $name, $extension ); var_dump($putFile);
列出文件
$listFiles = $awsBucket->listFiles( $bucket ); var_dump($listFiles);
如果您遇到403或400错误,您必须配置AWS控制台中的桶权限,以允许文件上传。
如果您想要一个运行或测试的环境,您可以构建和安装依赖项,如下所示
docker build --build-arg PHP_VERSION=8.3-rc-cli -t not-empty/aws-bucket-php-lib:php83 -f contrib/Dockerfile .
访问容器
docker run -v ${PWD}/:/var/www/html -it not-empty/aws-bucket-php-lib:php83 bash
验证是否已安装所有依赖项
composer install --no-dev --prefer-dist
在样本文件sample/aws-bucket-sample.php中填写您的凭据、区域和桶名称
... $config = [ 'credentials' => [ 'key' => '', //you must put your aws iam key here 'secret' => '', //you must put your aws iam secret here ], 'version' => 'latest', 'region' => 'us-east-1', //you must put your bucket region here ]; $bucket = 'my-bucket'; //you must put your bucket name here
并运行
php sample/aws-bucket-sample.php
开发
想要贡献?太好了!
项目使用简单的代码。更改您的文件时要小心更新!任何新代码都只能接受经过所有验证的代码。
为确保整个项目正常
首先,您需要构建一个正确安装所有依赖项的环境
docker build --build-arg PHP_VERSION=8.3-rc-cli -t not-empty/aws-bucket-php-lib:php83 -f contrib/Dockerfile .
访问容器
docker run -v ${PWD}/:/var/www/html -it not-empty/aws-bucket-php-lib:php83 bash
安装所有依赖项
composer install --dev --prefer-dist
运行所有验证
composer check
Not Empty Foundation - 自由代码,充实心灵