質問編集履歴

3

html訂正

2019/12/02 05:55

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -55,6 +55,8 @@
55
55
  <meta charset="utf-8">
56
56
 
57
57
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
58
+
59
+ </head>
58
60
 
59
61
 
60
62
 

2

ソースの修正

2019/12/02 05:55

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -42,7 +42,7 @@
42
42
 
43
43
  <?php
44
44
 
45
- session_start
45
+ session_start();
46
46
 
47
47
  ?>
48
48
 

1

ソースを追加しました。

2019/12/02 05:51

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -33,3 +33,113 @@
33
33
  他のWebのサンプル等も色々試してみましたが、Ajaxで進捗率が100%になるがupload.phpに推移しなかったり、いきなり100%になってしまったり、おそらくやり方が悪いのだと思いますが、なかなかに上手く動作しません。
34
34
 
35
35
  何か別のやり方、特別な設定等が必要なのでしょうか?
36
+
37
+
38
+
39
+ index.php
40
+
41
+ ```
42
+
43
+ <?php
44
+
45
+ session_start
46
+
47
+ ?>
48
+
49
+ <!doctype html>
50
+
51
+ <html lang="ja">
52
+
53
+ <head>
54
+
55
+ <meta charset="utf-8">
56
+
57
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
58
+
59
+
60
+
61
+ <body>
62
+
63
+ <form method="post" action="index.php" enctype="multipart/form-data">
64
+
65
+ <input id="uploadedFile" type="file" name="file">
66
+
67
+ <input type="hidden" name="<?php echo ini_get("session.upload_progress.name"); ?>" value="example" />
68
+
69
+ <span id="progress">0%</span>
70
+
71
+ <p><input type="submit" value="ファイルをアップする"></p>
72
+
73
+ </form>
74
+
75
+
76
+
77
+ <script type="text/javascript">
78
+
79
+ $(function() {
80
+
81
+ $("form").submit(function() {
82
+
83
+ var progress = $("#progress");
84
+
85
+
86
+
87
+ var f = function() {
88
+
89
+ $.getJSON("./progress.php", function(data) {
90
+
91
+ //console.dir(data);
92
+
93
+ if (data != null) {
94
+
95
+ progress.text(
96
+
97
+ "" + Math.round(100 * (data["bytes_processed"] / data["content_length"])) + "%"
98
+
99
+ );
100
+
101
+ if (!data["done"]) {
102
+
103
+ setTimeout(f, 200);
104
+
105
+ }
106
+
107
+ }
108
+
109
+ });
110
+
111
+ };
112
+
113
+
114
+
115
+ setTimeout(f, 300);
116
+
117
+ });
118
+
119
+ });
120
+
121
+ </script>
122
+
123
+ </body>
124
+
125
+ </html>
126
+
127
+ ```
128
+
129
+
130
+
131
+ progress.php
132
+
133
+ ```ここに言語を入力
134
+
135
+ <?php
136
+
137
+ session_start();
138
+
139
+ $key = ini_get("session.upload_progress.prefix")."example";
140
+
141
+ echo isset($_SESSION[$key]) ? json_encode($_SESSION[$key]) : json_encode(null);
142
+
143
+ ?>
144
+
145
+ ```