PHP code example of azure-oss / storage-blob
1. Go to this page and download the library: Download azure-oss/storage-blob 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/ */
azure-oss / storage-blob example snippets
use AzureOss\Storage\Blob\BlobServiceClient;
use AzureOss\Storage\Blob\Models\UploadBlobOptions;
$service = BlobServiceClient::fromConnectionString(
getenv('AZURE_STORAGE_CONNECTION_STRING')
);
$container = $service->getContainerClient('quickstart');
$container->createIfNotExists();
$blob = $container->getBlobClient('hello.txt');
$blob->upload(
'Hello from PHP OSS for Azure',
new UploadBlobOptions(contentType: 'text/plain')
);
$download = $blob->downloadStreaming();
$content = $download->content->getContents();
echo $content.PHP_EOL; // Hello from PHP OSS for Azure
foreach ($container->getBlobs() as $item) {
echo $item->name.PHP_EOL;
}
// Optional cleanup
$blob->deleteIfExists();
// $container->deleteIfExists();