回答編集履歴
2
type
answer
CHANGED
@@ -56,7 +56,7 @@
|
|
56
56
|
});
|
57
57
|
});
|
58
58
|
</script>
|
59
|
-
<form id="f1" action="
|
59
|
+
<form id="f1" action="recv.php" method="post" enctype="multipart/form-data">
|
60
60
|
<input type="hidden" name="group_no" value="10005">
|
61
61
|
<input type="file" name="f[]"><br>
|
62
62
|
<input type="file" name="f[]"><br>
|
1
追記
answer
CHANGED
@@ -6,4 +6,61 @@
|
|
6
6
|
ajaxで順番に送ってあげる必要があると思います。
|
7
7
|
|
8
8
|
ただ順番におくる意味があるかといわれると微妙です。
|
9
|
-
一緒におくって、サーバー側で順番に処理すればいいような気がします
|
9
|
+
一緒におくって、サーバー側で順番に処理すればいいような気がします
|
10
|
+
|
11
|
+
# 単純パターン
|
12
|
+
- send.html
|
13
|
+
```HTML
|
14
|
+
<form id="f1" action="recv.php" method="post" enctype="multipart/form-data">
|
15
|
+
<input type="hidden" name="group_no" value="10005">
|
16
|
+
<input type="file" name="f[]"><br>
|
17
|
+
<input type="file" name="f[]"><br>
|
18
|
+
<input type="file" name="f[]"><br>
|
19
|
+
<input type="submit" value="go">
|
20
|
+
</form>
|
21
|
+
```
|
22
|
+
- recv.php
|
23
|
+
```PHP
|
24
|
+
<?PHP
|
25
|
+
$group_no=filter_input(INPUT_POST,"group_no");
|
26
|
+
$uploads_dir = '/uploads';
|
27
|
+
if(count($_FILES)>0){
|
28
|
+
foreach($_FILES["f"]["tmp_name"] as $key=>$tmp_name){
|
29
|
+
if($_FILES["f"]["error"][$key]>0) continue;
|
30
|
+
$up=$uploads_dir."/".$group_no.($key+1);
|
31
|
+
echo "move_uploaded_file('$tmp_name','$up');\n";
|
32
|
+
//move_uploaded_file($tmp_name, $up); //実際にはこちらを利用
|
33
|
+
}
|
34
|
+
}
|
35
|
+
?>
|
36
|
+
```
|
37
|
+
|
38
|
+
# 画面遷移しない
|
39
|
+
- send.html
|
40
|
+
```HTML
|
41
|
+
<script>
|
42
|
+
$(function(){
|
43
|
+
$('#f1').on('submit',function(e){
|
44
|
+
e.preventDefault();
|
45
|
+
var fd=new FormData($(this).get(0));
|
46
|
+
$.ajax({
|
47
|
+
"url":$(this).attr('action'),
|
48
|
+
"type":"post",
|
49
|
+
"data":fd,
|
50
|
+
"cache":false,
|
51
|
+
"processData": false,
|
52
|
+
"contentType": false,
|
53
|
+
}).done(function(data){
|
54
|
+
console.log(data);
|
55
|
+
});
|
56
|
+
});
|
57
|
+
});
|
58
|
+
</script>
|
59
|
+
<form id="f1" action="y.php" method="post" enctype="multipart/form-data">
|
60
|
+
<input type="hidden" name="group_no" value="10005">
|
61
|
+
<input type="file" name="f[]"><br>
|
62
|
+
<input type="file" name="f[]"><br>
|
63
|
+
<input type="file" name="f[]"><br>
|
64
|
+
<input type="submit" value="go">
|
65
|
+
</form>
|
66
|
+
```
|