質問編集履歴

1

全文掲載

2018/11/19 07:36

投稿

nakabou33
nakabou33

スコア17

test CHANGED
File without changes
test CHANGED
@@ -39,3 +39,171 @@
39
39
  $dbh = null;
40
40
 
41
41
  ```
42
+
43
+
44
+
45
+ ```
46
+
47
+ //PHP 全文
48
+
49
+ <!DOCTYPE html>
50
+
51
+ <html lang ="en">
52
+
53
+
54
+
55
+ <body>
56
+
57
+ <form enctype="multipart/form-data" method="POST" action="index.php">
58
+
59
+ <input type ="file" name ="userfile">
60
+
61
+ <input type = "submit" value="upload">
62
+
63
+
64
+
65
+ <form action = "kensaku,php" method="post">
66
+
67
+ タイトル:<input type="text" name="nm">
68
+
69
+ <input type="submit" name="exec" value="検索">
70
+
71
+
72
+
73
+ </form>
74
+
75
+
76
+
77
+ <?php
78
+
79
+ if(isset($_FILES["userfile"]) and $_FILES["userfile"]["error"]==0){
80
+
81
+
82
+
83
+ $uploadDir = './userid/';
84
+
85
+ $uploadPath = $uploadDir . $_FILES['userfile']['name'];
86
+
87
+
88
+
89
+ if(!isset($_POST['submit'])){
90
+
91
+ if(move_uploaded_file(
92
+
93
+ $_FILES['userfile']['tmp_name'],
94
+
95
+ $uploadPath
96
+
97
+ )){
98
+
99
+ echo '成功です';
100
+
101
+
102
+
103
+ echo $uploadPath = __FILE__;
104
+
105
+ echo $title = basename($uploadPath);
106
+
107
+
108
+
109
+ try {
110
+
111
+ $dbh = new PDO('mysql:host=localhost;dbname=imagedb', 'root', '');
112
+
113
+ $sql = "INSERT INTO images (
114
+
115
+ id, title, description, userId,extention
116
+
117
+ ) VALUES (
118
+
119
+ '$uploadPath',
120
+
121
+ '$title',
122
+
123
+ 'description',
124
+
125
+ 'userId',
126
+
127
+ 'extention'
128
+
129
+ )";
130
+
131
+
132
+
133
+ $res = $dbh->query($sql);
134
+
135
+ } catch(PDOException $e) {
136
+
137
+ echo $e->getMessage();
138
+
139
+ die();
140
+
141
+ }
142
+
143
+ $dbh = null;
144
+
145
+ }else{
146
+
147
+ echo '失敗です';
148
+
149
+ }
150
+
151
+ }
152
+
153
+ }
154
+
155
+ echo "<br />\n";
156
+
157
+
158
+
159
+ $dir_path = './userid/';
160
+
161
+ if (is_dir($dir_path)){
162
+
163
+ if(is_readable($dir_path)){
164
+
165
+ $ch_dir = dir($dir_path);
166
+
167
+
168
+
169
+ while (false !== ($file_name = $ch_dir -> read())){
170
+
171
+ $ln_path = $ch_dir -> path . "/" .$file_name;
172
+
173
+
174
+
175
+ if (@getimagesize($ln_path)){
176
+
177
+
178
+
179
+ echo "<a href = \"imgview.php?d=" .urlencode(mb_convert_encoding($ln_path, "UTF-8")). "\" target = \"_blank\" >";
180
+
181
+ echo "<img src = \"" .$ln_path. "\" width=\"100\"></a> ";
182
+
183
+
184
+
185
+ }}
186
+
187
+ $ch_dir -> close();}
188
+
189
+ else{
190
+
191
+ echo "<p>" .htmlspecialchars($dir_path)." は読み込みが許可されていません。";}}
192
+
193
+ else{
194
+
195
+ echo 'DIR 画像がないよ';}
196
+
197
+
198
+
199
+ ?>
200
+
201
+
202
+
203
+ </body>
204
+
205
+ </html>
206
+
207
+
208
+
209
+ ```