LoginSignup
1
1

More than 5 years have passed since last update.

AzureStorage(BLOBストレージアカウント)にPHPでファイルを転送する

Last updated at Posted at 2018-06-18

AzureStorage(BLOBストレージアカウント)にPHPでファイルを転送する

Microsoft Azure Storage Exloprerのインストール

"Microsoft Azure Storage Exloprer"をインストールします。

  • Azure Storage ExplorerでOperating systemでOSを選択して"Download Storage Explorer free"からダウンロード
  • インストール後、"Microsoft Azure Storage Exloprer"を立ち上げます
  • "Connect to Azure Storage"という画面が表示されるので、デフォルト値(Add an Azure Accountにチェック、Azure environment:Azrue)のまま右下の"Sign in"をクリック
  • Sign in画面が表示、AzurePortalにログインしている"E-mail/password"を入力

コンテナの作成

BLOBではコンテナに対して、ファイルをアップロードするため事前に作成しておきます。

  • Microsoft Azure Storage ExloprerでStorage Accounts > アカウント名にアクセス
  • Blob Containersで右クリック > CreateBlobContainerでコンテナ名を入力

認証情報

AzurePortal画面で認証用の接続文字列の確認をします。

  • ストレージアカウント > アカウント名 > アクセスキー > key1「接続文字列」
  • コピーした際、文字列最後尾の";EndpointSuffix=core.windows.net"を含めると接続時にエラーとなりますので、削除して設定して下さい。

アップロード処理

今回はPHPで以下のように処理を書きました

composerで"microsoft/azure-storage-blob"をインストールしてください。

uploadStorage.php

$connectionString = "認証情報の文字列";
$container = "アップロード先のコンテナ名"

//Storageにアクセス
BlobRestProxy::createBlobService($connectionString);

$file = "/path/to/file";
$fileInfo = pathinfo($file);
$data = file_get_contents($file);

//ファイルアップロード
$blobRestProxy->createBlockBlob($container, $fileInfo['basename'], $data);

これで対象のファイルがStorageAccountにアップロードされると思います。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1