回答編集履歴
1
test
test
CHANGED
@@ -17,3 +17,59 @@
|
|
17
17
|
|
18
18
|
|
19
19
|
どういう意図かわからないところが散見されます
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
# sample
|
24
|
+
|
25
|
+
fetchで画像とコメントをおくる
|
26
|
+
|
27
|
+
```javascript
|
28
|
+
|
29
|
+
<script>
|
30
|
+
|
31
|
+
window.addEventListener('DOMContentLoaded', ()=>{
|
32
|
+
|
33
|
+
document.querySelector('#btn').addEventListener('click',e=>{
|
34
|
+
|
35
|
+
e.preventDefault();
|
36
|
+
|
37
|
+
var body=new FormData(e.target.form);
|
38
|
+
|
39
|
+
var method="post";
|
40
|
+
|
41
|
+
fetch("get_file.php",{body,method}).then(res=>res.text()).then(console.log);
|
42
|
+
|
43
|
+
});
|
44
|
+
|
45
|
+
});
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
</script>
|
50
|
+
|
51
|
+
<form id="f1" method="post" enctype="multipart/form-data">
|
52
|
+
|
53
|
+
<input type="file" name="myfile"><br>
|
54
|
+
|
55
|
+
<input type="text" name="mycomment" value="hogehoge"><br>
|
56
|
+
|
57
|
+
<input type="submit" value="send" id="btn">
|
58
|
+
|
59
|
+
</form>
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
- get_file.php
|
64
|
+
|
65
|
+
```PHP
|
66
|
+
|
67
|
+
<?PHP
|
68
|
+
|
69
|
+
print_r($_POST);
|
70
|
+
|
71
|
+
print_r($_FILES);
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
```
|