回答編集履歴
3
修正
test
CHANGED
@@ -126,11 +126,11 @@
|
|
126
126
|
|
127
127
|
if (isset($_FILES["upfile"])) {
|
128
128
|
|
129
|
-
save_jpeg($_FILES["upfile"]);
|
129
|
+
echo save_jpeg($_FILES["upfile"]);
|
130
130
|
|
131
131
|
} else {
|
132
132
|
|
133
|
-
show_form(1024 * 1024 * 3);
|
133
|
+
echo show_form(1024 * 1024 * 3);
|
134
134
|
|
135
135
|
}
|
136
136
|
|
2
追記
test
CHANGED
@@ -19,3 +19,125 @@
|
|
19
19
|
__FORM__; // ヒアドキュメントの末尾は行頭でなければなりません。
|
20
20
|
|
21
21
|
```
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
---
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
```php
|
30
|
+
|
31
|
+
<?php
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
function show_form($maxsize)
|
36
|
+
|
37
|
+
{
|
38
|
+
|
39
|
+
$html = <<< __FORM__
|
40
|
+
|
41
|
+
<form action="" method="POST" enctype="multipart/form-data">
|
42
|
+
|
43
|
+
upload jpeg data:<br/>
|
44
|
+
|
45
|
+
<input type="hidden" name="MAX_FILE_SIZE" value="{$maxsize}" />
|
46
|
+
|
47
|
+
<input type="file" name="upfile"><br/>
|
48
|
+
|
49
|
+
<input type="submit" value="Submit" />
|
50
|
+
|
51
|
+
</form>
|
52
|
+
|
53
|
+
__FORM__;
|
54
|
+
|
55
|
+
return $html;
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
function save_jpeg($files)
|
62
|
+
|
63
|
+
{
|
64
|
+
|
65
|
+
$tmp_file = $files['tmp_name'];
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
$fn = sprintf('%s.jpeg', uniqid());
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
$save_file = dirname(__FILE__) . '/' . $fn;
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
if (!is_uploaded_file($tmp_file)) {
|
78
|
+
|
79
|
+
throw new Exception("upload error");
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
86
|
+
|
87
|
+
$type = finfo_file($finfo, $tmp_file);
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
if ($type != "image/jpeg") {
|
92
|
+
|
93
|
+
throw new Exception("not jpeg");
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
if (!move_uploaded_file($tmp_file, $save_file)) {
|
98
|
+
|
99
|
+
throw new Exception("upload failed");
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
$html = "<h1>uploaded jpeg</h1>";
|
106
|
+
|
107
|
+
$html .= "<img src='{$fn}' />";
|
108
|
+
|
109
|
+
return $html;
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
?>
|
114
|
+
|
115
|
+
<!DOCTYPE html>
|
116
|
+
|
117
|
+
<html>
|
118
|
+
|
119
|
+
<head>
|
120
|
+
|
121
|
+
</head>
|
122
|
+
|
123
|
+
<body>
|
124
|
+
|
125
|
+
<?php
|
126
|
+
|
127
|
+
if (isset($_FILES["upfile"])) {
|
128
|
+
|
129
|
+
save_jpeg($_FILES["upfile"]);
|
130
|
+
|
131
|
+
} else {
|
132
|
+
|
133
|
+
show_form(1024 * 1024 * 3);
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
?>
|
138
|
+
|
139
|
+
</body>
|
140
|
+
|
141
|
+
</html>
|
142
|
+
|
143
|
+
```
|
1
追記
test
CHANGED
@@ -5,3 +5,17 @@
|
|
5
5
|
line NN と出るからといって、29 行目に問題があるとは限りません。
|
6
6
|
|
7
7
|
1 〜 29 行目にエラーがあります。
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
```php
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
<input type="submit" value="Submit" />
|
16
|
+
|
17
|
+
</form>
|
18
|
+
|
19
|
+
__FORM__; // ヒアドキュメントの末尾は行頭でなければなりません。
|
20
|
+
|
21
|
+
```
|