'한글이름'에 해당되는 글 1건

한글로 된 파일이름을 다운로드 할 때 예제 PHP 샘플소스입니다.

<?php
	if(!isset($_GET['filename'])) {
		echo "file not found";
		return;
	}
	$filename = $_GET['filename'];
	$filepath = dirname(__FILE__)."/파일경로/".$_GET['filename']; // 경로에 맞게 수정
	if(!file_exists($filepath)) {
		echo "file not found ". $filepath;
		return;
	} else {
		header("Content-Type: application/octet-stream");
		header("Content-Disposition: attachment; filename=\"$filename\"; filename*=UTF-8''".urlencode($_GET['filename']));
		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);
	}
?>

위 코드를 download.php 파일로 저장하고 호출은 download.php?filename=파일이름 이렇게 하시면 됩니다.

 

블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,