質問編集履歴

3

サンプルソースの追加

2018/01/26 09:18

投稿

makotookamura
makotookamura

スコア8

test CHANGED
File without changes
test CHANGED
@@ -28,7 +28,9 @@
28
28
 
29
29
 
30
30
 
31
- ```
31
+ ```php
32
+
33
+
32
34
 
33
35
  $file_path_SJIS = mb_convert_encoding($file_path, 'cp932', 'UTF-8');
34
36
 
@@ -71,3 +73,99 @@
71
73
 
72
74
 
73
75
  ![バージョンアップ後のphpinfo](81db2da77de916f6b396e8ab7cd0bf64.png)
76
+
77
+
78
+
79
+ ### 検証用のサンプルソース
80
+
81
+
82
+
83
+ 以下のソースで日本語を含むファイル名のファイルをアップロードしたときに、
84
+
85
+ ファイル名が文字化けしてしまいます。
86
+
87
+ (検証用に色々混じっていて、雑なコードですみません。。)
88
+
89
+
90
+
91
+ ```php
92
+
93
+ <?php
94
+
95
+ header('Content-Type: text/html; charset=utf-8');
96
+
97
+ $wkpath = __DIR__.'/';
98
+
99
+ $file_name = $_FILES['file']['name'];
100
+
101
+ $file_tmp = $_FILES['file']['tmp_name'];
102
+
103
+ $Result = "";
104
+
105
+ $file_name_path = mb_convert_encoding($wkpath.$file_name,'cp932','utf8');
106
+
107
+ if(move_uploaded_file( $file_tmp,$file_name_path))
108
+
109
+ {
110
+
111
+ $Result = "【OK】".mb_convert_encoding($file_name_path, 'utf8','cp932');
112
+
113
+ }
114
+
115
+ else
116
+
117
+ {
118
+
119
+ $Result = "【NG】".mb_convert_encoding($file_name_path, 'utf8','cp932');
120
+
121
+ }
122
+
123
+
124
+
125
+ ?>
126
+
127
+
128
+
129
+ <html>
130
+
131
+ <head>
132
+
133
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
134
+
135
+ </head>
136
+
137
+ <body>
138
+
139
+ <p></p>
140
+
141
+ <form action="" method="post" enctype="multipart/form-data" onsubmit="set()">
142
+
143
+ <input type="file" name="file" />
144
+
145
+ <input type="submit" value="アップロード実行" style="position: absolute; left: 320px; top: 8px"/>
146
+
147
+ </form>
148
+
149
+ <?php echo "アップロード結果:" ?>
150
+
151
+ </form>
152
+
153
+ <div>
154
+
155
+ <textarea cols="100" rows="4" style="overflow:scroll;" readonly><?php echo $file_name . "を受け付けました"; ?></textarea>
156
+
157
+ </div>
158
+
159
+
160
+
161
+ <div>
162
+
163
+ <?php echo $Result,"<br />\n"; ?>
164
+
165
+ </div>
166
+
167
+ </body>
168
+
169
+ </html>
170
+
171
+ ```

2

誤字の修正

2018/01/26 09:18

投稿

makotookamura
makotookamura

スコア8

test CHANGED
File without changes
test CHANGED
@@ -62,7 +62,7 @@
62
62
 
63
63
 
64
64
 
65
- ![バージョンアップ前のphpinfo](c7444a80196d74e8fa6c29c4a82893a7.png)](bb6a7682c318cd727f20489f36cd6374.png)
65
+ ![バージョンアップ前のphpinfo](c7444a80196d74e8fa6c29c4a82893a7.png)]
66
66
 
67
67
 
68
68
 

1

php.infoの情報を追記

2018/01/26 09:06

投稿

makotookamura
makotookamura

スコア8

test CHANGED
File without changes
test CHANGED
@@ -51,3 +51,23 @@
51
51
 
52
52
 
53
53
  mb_convert_encodingを外してみましたが、今度は別の文字化けされたファイルが出力されました。
54
+
55
+
56
+
57
+ ### php.info()で見たmbstringの設定
58
+
59
+
60
+
61
+ #### バージョンアップ前
62
+
63
+
64
+
65
+ ![バージョンアップ前のphpinfo](c7444a80196d74e8fa6c29c4a82893a7.png)](bb6a7682c318cd727f20489f36cd6374.png)
66
+
67
+
68
+
69
+ #### バージョンアップ後
70
+
71
+
72
+
73
+ ![バージョンアップ後のphpinfo](81db2da77de916f6b396e8ab7cd0bf64.png)