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 5 years have passed since last update.

PHP Codeigniter force_downloadでのIE文字化け対応

Posted at

■PHP Codeigniter

PHPのフレームワーク

■問題

download helper の[force_download]を使用し日本語ファイルをIEでダウンロードしようとすると文字化け

download.php
$file_path = '/data/てすと.csv';
force_download($file_path, null);

image.png

■対応

download.php
$file_path = '/data/てすと.csv';
$file_data = null;
$ua = $_SERVER['HTTP_USER_AGENT'];
if (strstr($ua, 'Trident') || strstr($ua, 'MSIE')) {
	/* IEの場合 */
	$file_data = file_get_contents($file_path);
	$file_name = basename($file_path);
	$file_path = mb_convert_encoding($file_name, 'SHIFT_JIS', 'UTF-8');
}
force_download($file_path, $file_data);

image.png

■さいごに

・自分用メモ
・IE対応はめんどくさい

0
0
1

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?