質問編集履歴
5
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -56,7 +56,7 @@
|
|
56
56
|
fwrite($fp, $image['body']);
|
57
57
|
fclose($fp);
|
58
58
|
|
59
|
-
// ここから、一時ファイルを加工して別ディレクトリに保存します。(
|
59
|
+
// ここから、一時ファイルを加工して別ディレクトリに保存します。(*)
|
60
60
|
|
61
61
|
}
|
62
62
|
|
4
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -56,7 +56,7 @@
|
|
56
56
|
fwrite($fp, $image['body']);
|
57
57
|
fclose($fp);
|
58
58
|
|
59
|
-
// ここから、一時ファイルを加工して別ディレクトリに保存します。
|
59
|
+
// ここから、一時ファイルを加工して別ディレクトリに保存します。(①)
|
60
60
|
|
61
61
|
}
|
62
62
|
|
3
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -18,7 +18,8 @@
|
|
18
18
|
|
19
19
|
誤解する表現でしたので、追記いたします。
|
20
20
|
|
21
|
+
|
21
|
-
<追記(
|
22
|
+
<追記(メール情報から画像をファイル保存するまでの処理>
|
22
23
|
```ここに言語を入力
|
23
24
|
<?php
|
24
25
|
$input = file_get_contents("php://stdin");
|
2
コード追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,4 +16,96 @@
|
|
16
16
|
file_get_contents、mail_mimeDecodeで画像を取得、保存した場合、
|
17
17
|
その画像情報から'orientation'の変更が可能か、という意味です。
|
18
18
|
|
19
|
-
誤解する表現でしたので、追記いたします。
|
19
|
+
誤解する表現でしたので、追記いたします。
|
20
|
+
|
21
|
+
<追記(コード)>
|
22
|
+
```ここに言語を入力
|
23
|
+
<?php
|
24
|
+
$input = file_get_contents("php://stdin");
|
25
|
+
$structure = mail_mimeDecode($input);
|
26
|
+
|
27
|
+
if (strtolower($structure->ctype_primary) == "multipart") {
|
28
|
+
$images = getImage($structure->parts);
|
29
|
+
}
|
30
|
+
|
31
|
+
reset($images);
|
32
|
+
// 拡張子を格納
|
33
|
+
$ext = '';
|
34
|
+
|
35
|
+
$count = 0;
|
36
|
+
|
37
|
+
$count_max = count($images);
|
38
|
+
|
39
|
+
foreach ($images as $image) {
|
40
|
+
if ($image['type'] == 'image/jpeg' || $image['type'] == 'image/gif' || $image['type'] == 'image/png') {
|
41
|
+
$count++;
|
42
|
+
|
43
|
+
|
44
|
+
// ファイルとして保存($pathDir_tmpImageは一時ファイルを保存するディレクトリ名です)
|
45
|
+
$tmp_path = tempnam($pathDir_tmpImage, 'img_');
|
46
|
+
if ($tmp_path == false) {
|
47
|
+
break;
|
48
|
+
}
|
49
|
+
$fp = fopen($tmp_path, 'w');
|
50
|
+
if ($fp == false) {
|
51
|
+
|
52
|
+
break;
|
53
|
+
}
|
54
|
+
|
55
|
+
fwrite($fp, $image['body']);
|
56
|
+
fclose($fp);
|
57
|
+
|
58
|
+
// ここから、一時ファイルを加工して別ディレクトリに保存します。
|
59
|
+
|
60
|
+
}
|
61
|
+
|
62
|
+
function mail_mimeDecode($input){
|
63
|
+
list($headers,$body) = splitBodyHeader($input);
|
64
|
+
return decode($headers, $body);
|
65
|
+
}
|
66
|
+
|
67
|
+
function splitBodyHeader($input){
|
68
|
+
if (preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $input, $match)) {
|
69
|
+
return array($match[1], $match[2]);
|
70
|
+
}
|
71
|
+
return false;
|
72
|
+
}
|
73
|
+
|
74
|
+
function getImage($parts) {
|
75
|
+
|
76
|
+
$images = array();
|
77
|
+
foreach( $parts as $part ){
|
78
|
+
print($part->ctype_primary. '/'.$part->disposition .'<br />');
|
79
|
+
// タイプ判別
|
80
|
+
if (isset($part->disposition) &&
|
81
|
+
(strtolower($part->disposition) == "attachment")) {
|
82
|
+
$images[] = array(
|
83
|
+
'type' => strtolower(sprintf("%s/%s",$part->ctype_primary,
|
84
|
+
$part->ctype_secondary)),
|
85
|
+
'name' => $part->ctype_paramaters['name'],
|
86
|
+
'body' => $part->body,
|
87
|
+
);
|
88
|
+
} else {
|
89
|
+
switch(strtolower($part->ctype_primary)){
|
90
|
+
case "image":
|
91
|
+
$images[] = array(
|
92
|
+
'type' => strtolower(sprintf("%s/%s", $part->ctype_primary,
|
93
|
+
$part->ctype_secondary)),
|
94
|
+
'name' => $part->crype_paramaters['name'],
|
95
|
+
'body' => $part->body,
|
96
|
+
);
|
97
|
+
break;
|
98
|
+
case "multipart":
|
99
|
+
$images = array_merge($images, getImage($part->parts));
|
100
|
+
break;
|
101
|
+
default:
|
102
|
+
break;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
}
|
107
|
+
return $images;
|
108
|
+
}
|
109
|
+
|
110
|
+
?>
|
111
|
+
```
|
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,4 +6,14 @@
|
|
6
6
|
|
7
7
|
調べてみると、iPhoneの場合は縦向きでも横向きで保存されるらしく、
|
8
8
|
'orientation'という値をいじれば良いところまではわかったのですが、
|
9
|
-
上記のやり方の場合、向きを直すことは可能でしょうか。
|
9
|
+
上記のやり方の場合、向きを直すことは可能でしょうか。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
<追記>
|
14
|
+
「上記のやり方の場合、向きを直すことは可能でしょうか。」
|
15
|
+
こちらですが、
|
16
|
+
file_get_contents、mail_mimeDecodeで画像を取得、保存した場合、
|
17
|
+
その画像情報から'orientation'の変更が可能か、という意味です。
|
18
|
+
|
19
|
+
誤解する表現でしたので、追記いたします。
|