質問編集履歴

5

修正

2018/05/29 03:29

投稿

avantgarden
avantgarden

スコア121

test CHANGED
File without changes
test CHANGED
@@ -114,7 +114,7 @@
114
114
 
115
115
 
116
116
 
117
- // ここから、一時ファイルを加工して別ディレクトリに保存します。(
117
+ // ここから、一時ファイルを加工して別ディレクトリに保存します。(
118
118
 
119
119
 
120
120
 

4

追記

2018/05/29 03:29

投稿

avantgarden
avantgarden

スコア121

test CHANGED
File without changes
test CHANGED
@@ -114,7 +114,7 @@
114
114
 
115
115
 
116
116
 
117
- // ここから、一時ファイルを加工して別ディレクトリに保存します。
117
+ // ここから、一時ファイルを加工して別ディレクトリに保存します。(①)
118
118
 
119
119
 
120
120
 

3

追記

2018/05/29 03:29

投稿

avantgarden
avantgarden

スコア121

test CHANGED
File without changes
test CHANGED
@@ -38,7 +38,9 @@
38
38
 
39
39
 
40
40
 
41
+
42
+
41
- <追記(ド)>
43
+ <追記(ル情報から画像をファイル保存するまでの処理>
42
44
 
43
45
  ```ここに言語を入力
44
46
 

2

コード追記

2018/05/29 03:27

投稿

avantgarden
avantgarden

スコア121

test CHANGED
File without changes
test CHANGED
@@ -35,3 +35,187 @@
35
35
 
36
36
 
37
37
  誤解する表現でしたので、追記いたします。
38
+
39
+
40
+
41
+ <追記(コード)>
42
+
43
+ ```ここに言語を入力
44
+
45
+ <?php
46
+
47
+ $input = file_get_contents("php://stdin");
48
+
49
+ $structure = mail_mimeDecode($input);
50
+
51
+
52
+
53
+ if (strtolower($structure->ctype_primary) == "multipart") {
54
+
55
+ $images = getImage($structure->parts);
56
+
57
+ }
58
+
59
+
60
+
61
+ reset($images);
62
+
63
+ // 拡張子を格納
64
+
65
+ $ext = '';
66
+
67
+
68
+
69
+ $count = 0;
70
+
71
+
72
+
73
+ $count_max = count($images);
74
+
75
+
76
+
77
+ foreach ($images as $image) {
78
+
79
+ if ($image['type'] == 'image/jpeg' || $image['type'] == 'image/gif' || $image['type'] == 'image/png') {
80
+
81
+ $count++;
82
+
83
+
84
+
85
+
86
+
87
+ // ファイルとして保存($pathDir_tmpImageは一時ファイルを保存するディレクトリ名です)
88
+
89
+ $tmp_path = tempnam($pathDir_tmpImage, 'img_');
90
+
91
+ if ($tmp_path == false) {
92
+
93
+ break;
94
+
95
+ }
96
+
97
+ $fp = fopen($tmp_path, 'w');
98
+
99
+ if ($fp == false) {
100
+
101
+
102
+
103
+ break;
104
+
105
+ }
106
+
107
+
108
+
109
+ fwrite($fp, $image['body']);
110
+
111
+ fclose($fp);
112
+
113
+
114
+
115
+ // ここから、一時ファイルを加工して別ディレクトリに保存します。
116
+
117
+
118
+
119
+ }
120
+
121
+
122
+
123
+ function mail_mimeDecode($input){
124
+
125
+ list($headers,$body) = splitBodyHeader($input);
126
+
127
+ return decode($headers, $body);
128
+
129
+ }
130
+
131
+
132
+
133
+ function splitBodyHeader($input){
134
+
135
+ if (preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $input, $match)) {
136
+
137
+ return array($match[1], $match[2]);
138
+
139
+ }
140
+
141
+ return false;
142
+
143
+ }
144
+
145
+
146
+
147
+ function getImage($parts) {
148
+
149
+
150
+
151
+ $images = array();
152
+
153
+ foreach( $parts as $part ){
154
+
155
+ print($part->ctype_primary. '/'.$part->disposition .'<br />');
156
+
157
+ // タイプ判別
158
+
159
+ if (isset($part->disposition) &&
160
+
161
+ (strtolower($part->disposition) == "attachment")) {
162
+
163
+ $images[] = array(
164
+
165
+ 'type' => strtolower(sprintf("%s/%s",$part->ctype_primary,
166
+
167
+ $part->ctype_secondary)),
168
+
169
+ 'name' => $part->ctype_paramaters['name'],
170
+
171
+ 'body' => $part->body,
172
+
173
+ );
174
+
175
+ } else {
176
+
177
+ switch(strtolower($part->ctype_primary)){
178
+
179
+ case "image":
180
+
181
+ $images[] = array(
182
+
183
+ 'type' => strtolower(sprintf("%s/%s", $part->ctype_primary,
184
+
185
+ $part->ctype_secondary)),
186
+
187
+ 'name' => $part->crype_paramaters['name'],
188
+
189
+ 'body' => $part->body,
190
+
191
+ );
192
+
193
+ break;
194
+
195
+ case "multipart":
196
+
197
+ $images = array_merge($images, getImage($part->parts));
198
+
199
+ break;
200
+
201
+ default:
202
+
203
+ break;
204
+
205
+ }
206
+
207
+ }
208
+
209
+
210
+
211
+ }
212
+
213
+ return $images;
214
+
215
+ }
216
+
217
+
218
+
219
+ ?>
220
+
221
+ ```

1

追記

2018/05/29 03:24

投稿

avantgarden
avantgarden

スコア121

test CHANGED
File without changes
test CHANGED
@@ -15,3 +15,23 @@
15
15
  'orientation'という値をいじれば良いところまではわかったのですが、
16
16
 
17
17
  上記のやり方の場合、向きを直すことは可能でしょうか。
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+ <追記>
26
+
27
+ 「上記のやり方の場合、向きを直すことは可能でしょうか。」
28
+
29
+ こちらですが、
30
+
31
+ file_get_contents、mail_mimeDecodeで画像を取得、保存した場合、
32
+
33
+ その画像情報から'orientation'の変更が可能か、という意味です。
34
+
35
+
36
+
37
+ 誤解する表現でしたので、追記いたします。