質問編集履歴

1

テスト

2017/06/14 04:32

投稿

Clover
Clover

スコア13

test CHANGED
File without changes
test CHANGED
@@ -1,158 +1,4 @@
1
1
  ```PHP
2
-
3
- require_once dirname(__FILE__) . '/vendor/autoload.php';
4
-
5
-
6
-
7
- use MicrosoftAzure\Storage\Common\ServicesBuilder;
8
-
9
- use MicrosoftAzure\Storage\Common\Exceptions\ServiceException;
10
-
11
- use MicrosoftAzure\Storage\Blob\Models\Block;
12
-
13
-
14
-
15
- define("CONNECTION_STRING", "ここにアクセスキー等");
16
-
17
- define("CONTAINERNAME", "movie");
18
-
19
- define("BLOCKSIZE", 4 * 1024 * 1024);
20
-
21
- define("PADLENGTH", 5);
22
-
23
-
24
-
25
- class AzureStorageBlob {
26
-
27
-
28
-
29
- public function upload($file_path) {
30
-
31
- define("FILENAME", $file_path);
32
-
33
- define("BLOCKBLOBNAME", basename(FILENAME));
34
-
35
-
36
-
37
- try {
38
-
39
- if (null == CONNECTION_STRING || "" == CONNECTION_STRING)
40
-
41
- {
42
-
43
- exit();
44
-
45
- }
46
-
47
-
48
-
49
- $blobRestProxy = ServicesBuilder::getInstance()->createBlobService(CONNECTION_STRING);
50
-
51
-
52
-
53
-
54
-
55
- if (!file_exists(FILENAME))
56
-
57
- {
58
-
59
- exit();
60
-
61
- }
62
-
63
-
64
-
65
- $handle = fopen(FILENAME, "r");
66
-
67
-
68
-
69
- // Upload the blob using blocks.
70
-
71
- $counter = 1;
72
-
73
- $blockIds = array();
74
-
75
-
76
-
77
- while (!feof($handle))
78
-
79
- {
80
-
81
- $blockId = str_pad($counter, PADLENGTH, "0", STR_PAD_LEFT);
82
-
83
-
84
-
85
- $block = new Block();
86
-
87
- $block->setBlockId(base64_encode($blockId));
88
-
89
- $block->setType("Uncommitted");
90
-
91
- array_push($blockIds, $block);
92
-
93
-
94
-
95
- $data = fread($handle, BLOCKSIZE);
96
-
97
-
98
-
99
- // Upload the block.
100
-
101
- $blobRestProxy->createBlobBlock(CONTAINERNAME, BLOCKBLOBNAME, base64_encode($blockId), $data);
102
-
103
- $counter++;
104
-
105
- }
106
-
107
-
108
-
109
- // Done creating the blocks. Close the file and commit the blocks.
110
-
111
- fclose($handle);
112
-
113
-
114
-
115
- $blobRestProxy->commitBlobBlocks(CONTAINERNAME, BLOCKBLOBNAME, $blockIds);
116
-
117
-
118
-
119
- }
120
-
121
- catch(ServiceException $serviceException)
122
-
123
- {
124
-
125
- echo "ServiceException encountered.\n";
126
-
127
- $code = $serviceException->getCode();
128
-
129
- $error_message = $serviceException->getMessage();
130
-
131
- echo "$code: $error_message";
132
-
133
- }
134
-
135
- catch (Exception $exception)
136
-
137
- {
138
-
139
- echo "Exception encountered.\n";
140
-
141
- $code = $exception->getCode();
142
-
143
- $error_message = $exception->getMessage();
144
-
145
- echo "$code: $error_message";
146
-
147
- }
148
-
149
-
150
-
151
- return True;
152
-
153
- } // end function upload
154
-
155
- } // end class AzureStorageBlob.php
156
2
 
157
3
  ```
158
4