微软对象PHP例子

GitHub库:https://github.com/Azure/azure-storage-php 微软自己说的那么复杂,其实很简单,直接放代码把.

$connectionString = '[连接字符串]';
$blobClient = BlobRestProxy::createBlobService($connectionString);
$createContainerOptions = new CreateContainerOptions();
$createContainerOptions->setPublicAccess(PublicAccessType::CONTAINER_AND_BLOBS);
$containerName = "blockblobs";
/* 创库 */
$blobClient->createContainer($containerName);
$result = $blobClient->listContainers();
dump($result->getContainers()[0]->getName());
/* 创文件 */
$result = $blobClient->createBlockBlob($containerName, 'hello.txt', "Hello Azure!");
dump($result->getETag());
/* 遍历 */
$listBlobsOptions = new ListBlobsOptions();
$listBlobsOptions->setPrefix("hello");
do {
    $result = $blobClient->listBlobs($containerName, $listBlobsOptions);
    foreach ($result->getBlobs() as $blob) {
        echo $blob->getName() . ": " . $blob->getUrl() . "<br />";
    }

    $listBlobsOptions->setContinuationToken($result->getContinuationToken());
} while ($result->getContinuationToken());
/* 打开 */
$blob = $blobClient->getBlob($containerName, "hello.txt");
dump(fgets($blob->getContentStream()));
/* 删除 */
$blobClient->deleteBlob($containerName, "hello.txt");
$blobClient->deleteContainer($containerName);

原文:微软对象PHP例子