✔️ IE 8, IE 11, 크롬 28에서 테스트하였습니다.
1 개요[ | ]
- PHP Force Download 2
- [Solved] UTF-8 filename problem
- PHP 파일 다운로드 구현 2 (한글 파일명 지원)
- IE에서 PHP 파일 다운로드 구현 + 한글 파일명 깨짐방지
2 쉘 확인[ | ]
Console
Copy
[root@zetawiki php]# echo $LANG
en_US.UTF-8
[root@zetawiki php]# ll 헬로_월드.txt
-rw-r--r-- 1 root root 13 Aug 4 20:00 헬로_월드.txt
3 소스 코드[ | ]
PHP
Copy
<?php
function mb_basename($path) { return end(explode('/',$path)); }
function utf2euc($str) { return iconv("UTF-8","cp949//IGNORE", $str); }
function is_ie() {
if(!isset($_SERVER['HTTP_USER_AGENT']))return false;
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) return true; // IE8
if(strpos($_SERVER['HTTP_USER_AGENT'], 'Windows NT 6.1') !== false) return true; // IE11
return false;
}
$filepath = './헬로_월드.txt';
$filesize = filesize($filepath);
$filename = mb_basename($filepath);
if( is_ie() ) $filename = utf2euc($filename);
header("Pragma: public");
header("Expires: 0");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: $filesize");
readfile($filepath);
4 같이 보기[ | ]
5 참고[ | ]
편집자 Jmnote 210.181.52.194 211.40.71.136 Jmnote bot 14.138.6.166
로그인하시면 댓글을 쓸 수 있습니다.