0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

画面文字コードがShift_JIS の場合、FormData を使ったファイルアップロードでファイル名が文字化けする

Posted at

ので、FormData の第3引数に encodeURIComponent したファイル名を設定、

test.html
<input type="file" id="file" />

<script>
let file = document.querySelector("#file");
let body = new FormData();
body.append("file1", file.files[0], encodeURIComponent("日本語.jpg"));
fetch("upload.php", {
    method: "POST",
    body: body,
}).then(function(res){
// 以下略...
</script>

受け側で urldecode して対応。

upload.php
<?php
$fileName = urldecode($_FILES["file1"]["name"]);
echo $fileName; // 日本語.jpg
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?