azure-oss/storage

Azure Storage PHP SDK

1.3.0 2024-11-10 16:45 UTC

This package is auto-updated.

Last update: 2024-11-14 13:24:14 UTC


README

Latest Version on Packagist Packagist Downloads GitHub Workflow Status

Tip

If you’re working with Laravel or Flysystem, check out our dedicated drivers.

Minimum Requirements

  • PHP 8.1 or above
  • Required PHP extensions
    • curl
    • json

Install

composer require azure-oss/storage

Quickstart

Create the BlobServiceClient

$blobServiceClient = BlobServiceClient::fromConnectionString("<connection string>");

Create a container

$containerClient = $blobServiceClient->getContainerClient('quickstart');
$containerClient->create();

List containers in a storage account

$containers = $blobServiceClient->getBlobContainers();

Upload a blob to a container

$blobClient = $containerClient->getBlobClient("hello.txt");
$blobClient->upload("world!");

// or using streams
$file = fopen('hugefile.txt', 'r');
$blobClient->upload($file);

List blobs in a container

$blobs = $containerClient->getBlobs();

// or with a prefix
$blobs = $containerClient->getBlobs('some/virtual/directory');

// and if you want both the blobs and virtual directories
$blobs = $containerClient->getBlobsByHierarchy('some/virtual/directory');

Download a blob

$result = $blobClient->downloadStreaming();

$props = $result->properties;
$content = $result->content->getContents();

Copy a blob

$sourceBlobClient = $containerClient->getBlobClient("source.txt");

// Can also be a different container
$targetBlobClient = $containerClient->getBlobClient("target.txt");
$targetBlobClient->copyFromUri($sourceBlobClient->uri);

Generate and use a Service SAS

$sas = $blobClient->generateSasUri(
    BlobSasBuilder::new()
        ->setPermissions(new BlobSasPermissions(read: true))
        ->setExpiresOn((new \DateTime())->modify("+ 15min")),
);

$sasBlobClient = new BlobClient($sas);

Generate and use an Account SAS

$sas = $blobServiceClient->generateAccountSasUri(
    AccountSasBuilder::new()
        ->setPermissions(new AccountSasPermissions(list: true))
        ->setResourceTypes(new AccountSasResourceTypes(service: true))
        ->setExpiresOn((new \DateTime())->modify("+ 15min")),
);

$sasServiceClient = new BlobServiceClient($sas);

Delete a container

$containerClient->delete();

Documentation

For more information visit the documentation at azure-oss.github.io.

Support

Do you need help, do you want to talk to us, or is there anything else?

Join us at:

License

Azure-Storage-PHP is released under the MIT License. See LICENSE for details.

PHP Version Support Policy

The maintainers of this package add support for a PHP version following its initial release and drop support for a PHP version once it has reached its end of security support.

Backward compatibility promise

Azure-Storage-PHP is using Semver. This means that versions are tagged with MAJOR.MINOR.PATCH. Only a new major version will be allowed to break backward compatibility (BC).

Classes marked as @experimental or @internal are not included in our backward compatibility promise. You are also not guaranteed that the value returned from a method is always the same. You are guaranteed that the data type will not change.

PHP 8 introduced named arguments, which increased the cost and reduces flexibility for package maintainers. The names of the arguments for methods in the library are not included in our BC promise.