not-empty/aws-bucket-php-lib

PHP 库,用于连接和使用 AWS S3 Bucket

7.0.0 2023-11-27 11:22 UTC

This package is auto-updated.

Last update: 2024-09-27 13:17:39 UTC


README

Latest Version codecov CI Build Downloads Old Downloads PRs Welcome Packagist License (custom server)

PHP 库,用于连接和使用 AWS S3 Bucket。

安装

版本 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 基金会 - 免费代码,满腔热血