在php中连接到Windows Azure存储


Connecting to a Windows Azure storage in php

我写了这样一个php代码语句来连接Windows Azure存储帐户。但是当我运行它时,它会导致页面重定向。

$blob = new Microsoft_WindowsAzure_Storage_Blob(
'blob.core.windows.net',
'http://myaccount.blob.core.windows.net/',
'myaccountkey'
);

我解决不了这个问题。

我该如何解决这个问题?

谢谢…

请看下面的例子。它连接到一个存储帐户,并创建一个名为hasan的blob容器。请使用您的帐户名和密钥进行尝试。

<?php
require_once 'WindowsAzure.php';
use WindowsAzure'Common'ServicesBuilder;
use WindowsAzure'Common'ServiceException;
use WindowsAzure'Blob'Models'SetBlobPropertiesOptions;
try {
  $containerName = "hasan";
  $connectionString = 'DefaultEndpointsProtocol=http;AccountName=<youraccountname>;AccountKey=<youraccountkey>';
  $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString); 
 $ok = $blobRestProxy->createContainer($containerName);
  echo "Error : " . $ok;
  }
catch(ServiceException $e){
$code = $e->getCode();
    $error_message = $e->getMessage();
    echo $code.": ".$error_message."<br />";
}  
?>