PHP code example of consilience / flysystem-azure-file-storage

1. Go to this page and download the library: Download consilience/flysystem-azure-file-storage 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/ */

    

consilience / flysystem-azure-file-storage example snippets


use League\Flysystem\Filesystem;
use Consilience\Flysystem\Azure\AzureFileAdapter;
use MicrosoftAzure\Storage\File\FileRestProxy;
use Illuminate\Support\ServiceProvider;

// A helper method for constructing the connectionString may be usedful,
// if there is a demand.

$connectionString = sprintf(
    'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s',
    '{storage account name}',
    '{file storage key}'
);

$config = [
    'endpoint' => $connectionString,
    'container' => '{file share name}',
    // Optional to prevent directory deletion recursively deleting
    // all descendant files and direcories.
    //'disableRecursiveDelete' => true,
    // Optional driver options can also be added here. e.g. CacheControl, Metadata.
];

$fileService = FileRestProxy::createFileService(
    $connectionString,
    [] // $optionsWithMiddlewares
);

$filesystem = new Filesystem(new AzureFileAdapter(
    $fileService,
    $config,
    'optional-directory-prefix'
));

// Now the $filesystem object can be used as a standard
// Flysystem file system.
// See https://flysystem.thephpleague.com/api/

// A few examples:

$content    = $filesystem->read('path/to/my/file.txt');
$resource   = $filesystem->readResource('path/to/my/file.txt');
$success    = $filesystem->createDir('new/directory/here');
$success    = $filesystem->rename('path/to/my/file.txt', 'some/other/folder/another.txt');

// The URL of a file can be found like this:

$url = $filesystem->getAdapter()->getUrl('path/to/my/foo.bar');