맛집 여행 캠핑 일상 생활

PHP 한글파일(hwp) 다운로드시 브라우저에서 열리는 문제 본문

LAMP

PHP 한글파일(hwp) 다운로드시 브라우저에서 열리는 문제

영은파더♥ 2016. 10. 20. 17:43

한글파일(hwp) 다운로드시 브라우저에서 열리는 문제


hwp 파일은 <a href="sample.hwp">다운로드</a> 로 클릭하면 웹화면에 그냥 뿌려진다.

이런 경우라면 아래 처럼 해주자.


▶ download.php

<?

$filepath = $_GET['filepath'];

if(!file_exists($filepath)) {

header("Content-Type: application/octet-stream");

header("Content-Disposition: attachment; filename=$filepath");

header("Content-Transfer-Encoding: binary");

header("Content-Length: ".(string)filesize($filepath));

header("Cache-Control: cache, must-revalidate");

header("Pragma: no-cache");

header("Expires: 0");

readfile($filepath);

}

?>

$filepath 는 $_GET 이나 $_POST 로 받아오면 된다.


Trackback : | Comments :