GitHub库:https://github.com/Azure/azure-storage-php 微软自己说的那么复杂,其实很简单,直接放代码把.
1 | $connectionString = '[连接字符串]' ; |
2 | $blobClient = BlobRestProxy::createBlobService( $connectionString ); |
3 | $createContainerOptions = new CreateContainerOptions(); |
4 | $createContainerOptions ->setPublicAccess(PublicAccessType::CONTAINER_AND_BLOBS); |
5 | $containerName = "blockblobs" ; |
7 | $blobClient ->createContainer( $containerName ); |
8 | $result = $blobClient ->listContainers(); |
9 | dump( $result ->getContainers()[0]->getName()); |
11 | $result = $blobClient ->createBlockBlob( $containerName , 'hello.txt' , "Hello Azure!" ); |
12 | dump( $result ->getETag()); |
14 | $listBlobsOptions = new ListBlobsOptions(); |
15 | $listBlobsOptions ->setPrefix( "hello" ); |
17 | $result = $blobClient ->listBlobs( $containerName , $listBlobsOptions ); |
18 | foreach ( $result ->getBlobs() as $blob ) { |
19 | echo $blob ->getName() . ": " . $blob ->getUrl() . "<br />" ; |
22 | $listBlobsOptions ->setContinuationToken( $result ->getContinuationToken()); |
23 | } while ( $result ->getContinuationToken()); |
25 | $blob = $blobClient ->getBlob( $containerName , "hello.txt" ); |
26 | dump( fgets ( $blob ->getContentStream())); |
28 | $blobClient ->deleteBlob( $containerName , "hello.txt" ); |
29 | $blobClient ->deleteContainer( $containerName ); |
原文:微软对象PHP例子