PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

API Examples

This topic lists some examples of using the Zend_Service_WindowsAzure_Storage_Blob class. Other features are available in the download package, as well as a detailed API documentation of those features.

Creating a storage container

Using the following code, a blob storage container can be created on development storage.

Example 888. Creating a storage container

<?php
$storageClient 
= new Zend_Service_WindowsAzure_Storage_Blob();
$result $storageClient->createContainer('testcontainer');

echo 
'Container name is: ' $result->Name;

Deleting a storage container

Using the following code, a blob storage container can be removed from development storage.

Example 889. Deleting a storage container

<?php
$storageClient 
= new Zend_Service_WindowsAzure_Storage_Blob();
$storageClient->deleteContainer('testcontainer');

Storing a blob

Using the following code, a blob can be uploaded to a blob storage container on development storage. Note that the container has already been created before.

Example 890. Storing a blob

<?php
$storageClient 
= new Zend_Service_WindowsAzure_Storage_Blob();

// upload /home/maarten/example.txt to Azure
$result $storageClient->putBlob(
    
'testcontainer''example.txt''/home/maarten/example.txt'
);

echo 
'Blob name is: ' $result->Name;

Copying a blob

Using the following code, a blob can be copied from inside the storage account. The advantage of using this method is that the copy operation occurs in the Azure cloud and does not involve downloading the blob. Note that the container has already been created before.

Example 891. Copying a blob

<?php
$storageClient 
= new Zend_Service_WindowsAzure_Storage_Blob();

// copy example.txt to example2.txt
$result $storageClient->copyBlob(
    
'testcontainer''example.txt''testcontainer''example2.txt'
);

echo 
'Copied blob name is: ' $result->Name;

Downloading a blob

Using the following code, a blob can be downloaded from a blob storage container on development storage. Note that the container has already been created before and a blob has been uploaded.

Example 892. Downloading a blob

<?php
$storageClient 
= new Zend_Service_WindowsAzure_Storage_Blob();

// download file to /home/maarten/example.txt
$storageClient->getBlob(
    
'testcontainer''example.txt''/home/maarten/example.txt'
);

Making a blob publicly available

By default, blob storage containers on Windows Azure are protected from public viewing. If any user on the Internet should have access to a blob container, its ACL can be set to public. Note that this applies to a complete container and not to a single blob!

Using the following code, blob storage container ACL can be set on development storage. Note that the container has already been created before.

Example 893. Making a blob publicly available

<?php
$storageClient 
= new Zend_Service_WindowsAzure_Storage_Blob();

// make container publicly available (enumerate all blobs and read blob data)
$storageClient->setContainerAcl('testcontainer'Zend_Service_WindowsAzure_Storage_Blob::ACL_PUBLIC_CONTAINER);

Zend Framework