teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

サンプルソースの追加

2018/01/26 09:18

投稿

makotookamura
makotookamura

スコア8

title CHANGED
File without changes
body CHANGED
@@ -13,7 +13,8 @@
13
13
 
14
14
  これまでmove_uploaded_file()の引数のファイル名をmb_convert_encoding()でutf8->cp932に変換して日本語ファイル名に対応していました。
15
15
 
16
- ```
16
+ ```php
17
+
17
18
  $file_path_SJIS = mb_convert_encoding($file_path, 'cp932', 'UTF-8');
18
19
  move_uploaded_file( [元ファイル], $file_path_SJIS);
19
20
  ```
@@ -34,4 +35,52 @@
34
35
 
35
36
  #### バージョンアップ後
36
37
 
37
- ![バージョンアップ後のphpinfo](81db2da77de916f6b396e8ab7cd0bf64.png)
38
+ ![バージョンアップ後のphpinfo](81db2da77de916f6b396e8ab7cd0bf64.png)
39
+
40
+ ### 検証用のサンプルソース
41
+
42
+ 以下のソースで日本語を含むファイル名のファイルをアップロードしたときに、
43
+ ファイル名が文字化けしてしまいます。
44
+ (検証用に色々混じっていて、雑なコードですみません。。)
45
+
46
+ ```php
47
+ <?php
48
+ header('Content-Type: text/html; charset=utf-8');
49
+ $wkpath = __DIR__.'/';
50
+ $file_name = $_FILES['file']['name'];
51
+ $file_tmp = $_FILES['file']['tmp_name'];
52
+ $Result = "";
53
+ $file_name_path = mb_convert_encoding($wkpath.$file_name,'cp932','utf8');
54
+ if(move_uploaded_file( $file_tmp,$file_name_path))
55
+ {
56
+ $Result = "【OK】".mb_convert_encoding($file_name_path, 'utf8','cp932');
57
+ }
58
+ else
59
+ {
60
+ $Result = "【NG】".mb_convert_encoding($file_name_path, 'utf8','cp932');
61
+ }
62
+
63
+ ?>
64
+
65
+ <html>
66
+ <head>
67
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
68
+ </head>
69
+ <body>
70
+ <p></p>
71
+ <form action="" method="post" enctype="multipart/form-data" onsubmit="set()">
72
+ <input type="file" name="file" />
73
+ <input type="submit" value="アップロード実行" style="position: absolute; left: 320px; top: 8px"/>
74
+ </form>
75
+ <?php echo "アップロード結果:" ?>
76
+ </form>
77
+ <div>
78
+ <textarea cols="100" rows="4" style="overflow:scroll;" readonly><?php echo $file_name . "を受け付けました"; ?></textarea>
79
+ </div>
80
+
81
+ <div>
82
+ <?php echo $Result,"<br />\n"; ?>
83
+ </div>
84
+ </body>
85
+ </html>
86
+ ```

2

誤字の修正

2018/01/26 09:18

投稿

makotookamura
makotookamura

スコア8

title CHANGED
File without changes
body CHANGED
@@ -30,7 +30,7 @@
30
30
 
31
31
  #### バージョンアップ前
32
32
 
33
- ![バージョンアップ前のphpinfo](c7444a80196d74e8fa6c29c4a82893a7.png)](bb6a7682c318cd727f20489f36cd6374.png)
33
+ ![バージョンアップ前のphpinfo](c7444a80196d74e8fa6c29c4a82893a7.png)]
34
34
 
35
35
  #### バージョンアップ後
36
36
 

1

php.infoの情報を追記

2018/01/26 09:06

投稿

makotookamura
makotookamura

スコア8

title CHANGED
File without changes
body CHANGED
@@ -24,4 +24,14 @@
24
24
 
25
25
  ### 試したこと
26
26
 
27
- mb_convert_encodingを外してみましたが、今度は別の文字化けされたファイルが出力されました。
27
+ mb_convert_encodingを外してみましたが、今度は別の文字化けされたファイルが出力されました。
28
+
29
+ ### php.info()で見たmbstringの設定
30
+
31
+ #### バージョンアップ前
32
+
33
+ ![バージョンアップ前のphpinfo](c7444a80196d74e8fa6c29c4a82893a7.png)](bb6a7682c318cd727f20489f36cd6374.png)
34
+
35
+ #### バージョンアップ後
36
+
37
+ ![バージョンアップ後のphpinfo](81db2da77de916f6b396e8ab7cd0bf64.png)