PHP警告:require_once(WindowsAzure / Blob / Models / BlockList.php):无法打开流

时间:2017-04-18 17:53:29

标签: php azure-storage-blobs

我使用了azure-sdk-for-php库,我收到此错误 - 警告:require_once(WindowsAzure / Blob / Models / BlockList.php):无法打开流:没有这样的文件或目录。

我的代码如下 -

define("__BLOBNAME__", "BLOBNAME");
define("__CONTAINERNAME__", "CONTAINERNAME");
define("__BLOBKEY__", "BLOBKEY");

//require_once('WindowsAzure\WindowsAzure.php');
use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Common\ServiceException;
use WindowsAzure\Common\CloudConfigurationManager;
use WindowsAzure\Blob\Models\Block;
use WindowsAzure\Blob\Models\CreateContainerOptions;
use WindowsAzure\Blob\Models\ListContainersOptions;
use WindowsAzure\Blob\Models\CreateBlobOptions;
use WindowsAzure\Blob\Models\CommitBlobBlocksOptions;

use WindowsAzure\Blob\Models\BlobProperties;


$connectionString = "DefaultEndpointsProtocol=http;AccountName=" . __BLOBNAME__ . ";AccountKey=" . __BLOBKEY__ . "";

if (null == $connectionString || "" == $connectionString) {
    echo "Did not find a connection string whose name is 'StorageConnectionString'.";
    exit();
}

// Create blob REST proxy.
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);

try {
    // List blobs.
    $blob_list = $blobRestProxy->listBlobs(__CONTAINERNAME__);
    $blobs = $blob_list->getBlobs();

    // iterate over blobs
    foreach ($blobs as $blob) {
        $options = new WindowsAzure\Blob\Models\CreateBlobOptions();
        $options->setBlobCacheControl("public, max-age=604800");
        echo 'setting ... ';
        $blobRestProxy->setBlobProperties(__CONTAINERNAME__,$blob->getName(), $options);
    }

} catch (ServiceException $e) {
    // Handle exception based on error codes and messages.
    // Error codes and messages are here:
    // http://msdn.microsoft.com/library/azure/dd179439.aspx
    $code = $e->getCode();
    $error_message = $e->getMessage();
    echo $code . ": " . $error_message;
}

1 个答案:

答案 0 :(得分:0)

您似乎无法加载SDK文件。

解决依赖关系的推荐方法是使用Composer package manager安装它们。

  • 在项目的根目录中创建名为 composer.json 的文件,并将以下代码添加到其中:

    json { "require": {
    "microsoft/windowsazure": "^0.5" }
    }

  • 在项目根目录中下载 composer.phar

  • 打开命令提示符并在项目根目录

    中执行此操作

    php composer.phar install

然后在代码中加载SDK:

require_once "vendor/autoload.php";