質問編集履歴

1

文字追加

2021/11/12 10:00

投稿

alyssa703957
alyssa703957

スコア12

test CHANGED
File without changes
test CHANGED
@@ -74,6 +74,162 @@
74
74
 
75
75
  ```
76
76
 
77
+ insert-img-chat.php↓
78
+
79
+ ```
80
+
81
+ <?php
82
+
83
+ session_start();
84
+
85
+
86
+
87
+
88
+
89
+ if(isset($_SESSION['user_unique_id'])){
90
+
91
+ require_once(ROOT_PATH .'Controllers/UserController.php');
92
+
93
+ $user = new UserController();
94
+
95
+ $user->InsertMsgImg();
96
+
97
+
98
+
99
+ }
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+ ?>
108
+
109
+ ```
110
+
111
+ insert-img-chat.phpにおける$user->InsertMsgImg()の処理部分が以下です。
112
+
113
+
114
+
115
+ ```controller
116
+
117
+ public function InsertMsgImg(){
118
+
119
+ $users = $this->PrivateChatRoom->insert_msg_img();
120
+
121
+ return $users;
122
+
123
+ }
124
+
125
+ ```
126
+
127
+ ```ここに言語を入力
128
+
129
+ public function insert_msg_img(){
130
+
131
+ if(isset($_POST['outgoing_msg_id'])){
132
+
133
+ $outgoing_msg_id = $_POST['outgoing_msg_id'];
134
+
135
+ }
136
+
137
+ if(isset($_POST['incoming_msg_id'])){
138
+
139
+ $incoming_msg_id = $_POST['incoming_msg_id'];
140
+
141
+ }
142
+
143
+ //画像送信
144
+
145
+ if($_FILES['msg_img']){
146
+
147
+ $msg_img_name = $_FILES['msg_img']['name'];
148
+
149
+ $msg_img_type = $_FILES['msg_img']['type'];
150
+
151
+ $msg_img_tmp_name = $_FILES['msg_img']['tmp_name'];
152
+
153
+
154
+
155
+ $msg_img_explode = explode('.',$msg_img_name);
156
+
157
+ $msg_img_txt = end($msg_img_explode);
158
+
159
+ $extensions = ["png","jpag","jpg"];
160
+
161
+
162
+
163
+ if(in_array($msg_img_txt,$extensions) === true){
164
+
165
+ $time = time();
166
+
167
+ $new_img_name = $time.$msg_img_name;
168
+
169
+ if(move_uploaded_file($msg_img_tmp_name,"img/".$new_img_name)){
170
+
171
+ $msg_img = $new_img_name;
172
+
173
+
174
+
175
+ }
176
+
177
+ }
178
+
179
+ }
180
+
181
+
182
+
183
+
184
+
185
+ if(!empty($msg_img)){
186
+
187
+ $sql = "INSERT INTO $this->table(outgoing_msg_id,incoming_msg_id,msg_img)
188
+
189
+ VALUES(:outgoing_msg_id,:incoming_msg_id,:msg_img)";
190
+
191
+ $sth = $this->dbh->prepare($sql);
192
+
193
+ }
194
+
195
+
196
+
197
+
198
+
199
+ $this->dbh->beginTransaction();
200
+
201
+ try {
202
+
203
+ $sth = $this->dbh->prepare($sql);
204
+
205
+ $sth->bindParam(':outgoing_msg_id', $outgoing_msg_id, PDO::PARAM_INT);
206
+
207
+ $sth->bindParam(':incoming_msg_id', $incoming_msg_id, PDO::PARAM_INT);
208
+
209
+ $sth->bindParam(':msg_img', $msg_img, PDO::PARAM_STR);
210
+
211
+
212
+
213
+ $result = $sth->execute();
214
+
215
+ $this->dbh->commit();
216
+
217
+ return $result;
218
+
219
+ } catch (\PDOException $e) {
220
+
221
+ echo '更新失敗'.$e->getMessage();
222
+
223
+ $this->dbh->rollBack();
224
+
225
+ exit();
226
+
227
+ }
228
+
229
+ }
230
+
231
+ ```
232
+
77
233
  insert-img-chat.phpに遷移はデバックでできています。
78
234
 
79
235
  insert-img-chat.php内でのSQL実行に際に$_filesの値が取得できません。