PHP code example of arquivei / flysystem-php

1. Go to this page and download the library: Download arquivei/flysystem-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arquivei / flysystem-php example snippets




$gcsStorage = new \Arquivei\Flysystems\ArquiveiStorage\Adapters\GoogleCloudStorage(
    new \Google\Cloud\Storage\StorageClient([
        'projectId' => 'my-project',
        'keyFilePath' => './auth.json'
    ])
);

$gcsStorage->setBucket('my-bucket');

$gcsStorage->putObject('data', '2019/key/');


$awsStorage = new \Arquivei\Flysystems\ArquiveiStorage\Adapters\AmazonAwsStorage(
    new \Aws\S3\S3Client([
        'key' => 'my-key',
        'secret' => 'my-secret',
        'region' => 'my-region',
        'version' => 'my-version'
    ])
);

$awsStorage->setBucket('my-bucket');

$awsStorage->putObject('data', '2019/key/');


'providers' => [
    Arquivei\Flysystems\GoogleCloudStorage\GoogleCloudStorageProvider::class,
]

'gcs' => [
    'driver' => 'gcs',
    'project_id' => env('GOOGLE_CLOUD_PROJECT_ID', 'your-project-id'),
    'key_file' => env('GOOGLE_CLOUD_KEY_FILE', null),
    'bucket' => env('GOOGLE_CLOUD_STORAGE_BUCKET', 'your-bucket'),
    'path_prefix' => env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX', null),
    'storage_api_uri' => env('GOOGLE_CtestingLOUD_STORAGE_API_URI', null), 
    'visibility' =>  env('GOOGLE_CLOUD_STORAGE_API_URI', 'private'), 
],

class IlluminateStorageAdapter
{

    private $storage;

    public function __construct()
    {
        $client = \Storage::cloud()
            ->getDriver()
            ->getAdapter()
            ->getClient();

        if ($client instanceof StorageClient) {
            $this->storage = new GoogleCloudStorage($client);
        }

        if ($client instanceof S3Client) {
            $this->storage = new AmazonAwsStorage($client);
        }

        if((!$client instanceof StorageClient) && (!$client instanceof S3Client)){
            throw new StorageNotFoundException();
        }
    }

    public function setBucket(String $bucket) : IlluminateStorageAdapter
    {
        $this->storage->setBucket($bucket);
        return $this;
    }

    public function setBasePath(String $basePath) : IlluminateStorageAdapter
    {
        $this->storage->setBasePath($basePath);
        return $this;
    }

    public function getObjectAsync(array $keys): array
    {
        return $this->storage->getObjectAsync($keys);
    }

    public function putObject(String $data, String $key, String $acl = "private") : String
    {
        return $this->storage->putObject($data, $key, $acl);
    }
}
bash
composer