azure-oss / storage
Azure Storage PHP SDK
Installs: 36 065
Dependents: 1
Suggesters: 0
Security: 0
Stars: 18
Watchers: 4
Forks: 5
Open Issues: 0
Requires
- php: ^8.1
- ext-curl: *
- ext-json: *
- ext-simplexml: *
- caseyamcl/guzzle_retry_middleware: ^2.10
- guzzlehttp/guzzle: ^7.8
Requires (Dev)
- laravel/pint: 1.18.1
- phpbench/phpbench: ^1.3
- phpstan/phpstan: ^1.11
- phpstan/phpstan-deprecation-rules: ^1.2
- phpstan/phpstan-strict-rules: ^1.6
- phpunit/phpunit: ^10.5
This package is auto-updated.
Last update: 2024-12-02 19:44:17 UTC
README
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.