Skip to content

Instantly share code, notes, and snippets.

@caillioux
Last active August 25, 2020 14:13
Show Gist options
  • Save caillioux/b41130b8c61347aa75c425afda1ae01d to your computer and use it in GitHub Desktop.
Save caillioux/b41130b8c61347aa75c425afda1ae01d to your computer and use it in GitHub Desktop.
<?php
include 'vendor/autoload.php';
use Aws\S3\S3Client;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\Filesystem;
$client = new S3Client([
'credentials' => [
'key' => '*************',
'secret' => '****************',
],
'region' => 'fr-par',
'version' => 'latest',
'endpoint' => 'https://s3.fr-par.scw.cloud',
]);
$adapter = new AwsS3Adapter($client, 'your-bucket');
$filesystem = new Filesystem($adapter);
$stream = fopen('readme.md', 'r+');
$filesystem->writeStream(
'uploads/readme.md',
$stream
);
if (is_resource($stream)) {
fclose($stream);
}
@caillioux
Copy link
Author

Ce qu'il faut savoir :

  • league/flysystem est le paquet PHP qui offre une abtraction de système de fichier pour le cloud
  • league/flysystem-aws-s3-v3 offre le support de S3 (habituellement Amazon S3, le leader sur le marché)
  • S3 est un protocole, d'autres cloud providers comme Scaleway l'implémentent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment