download.php
<?
function goBack($msg='', $url='') {
echo "<script>";
if($msg) echo 'alert("'.$msg.'");';
if($home_url) echo 'location.replace("'.$home_url.'");';
else echo 'history.go(-1);';
echo "</script>";
}
if(!$_SERVER["HTTP_REFERER"] || !ereg(str_replace(".","\\.",$_SERVER["HTTP_HOST"]), $_SERVER["HTTP_REFERER"])) {
goBack("정상적인 방법으로 다운로드해 주세요.");
exit;
}
$dir = "/home/www/seongpo/htdocs/Main_Board/Notice/data/$notice/"; // 파일이 저장되어 있는 폴더 설정
$real_name = stripslashes($data_file);
$save_name = $dir.stripslashes($data_file);
if(!file_exists($save_name)) {
goBack("다운로드할 파일을 찾을 수 없습니다. $save_name ");
exit;
} else {// 파일이 있으면 다운로드
if(strstr($HTTP_USER_AGENT, "MSIE 5.5")) {
header("Content-Type: doesn/matter");
header("Content-Disposition: filename=$data_file");
header("Content-Transfer-Encoding: binary");
header("Pragma: no-cache");
header("Expires: 0");
} else {
Header("Content-type: file/unknown");
Header("Content-Disposition: attachment; filename=$data_file");
Header("Content-Description: PHP3 Generated Data");
header("Pragma: no-cache");
header("Expires: 0");
}
$fp = fopen($save_name, "r");
if(!fpassthru($fp)) fclose($fp);
}
?>
링크
$data_file = "<a href='$home_url/download.php?data_file=$data_array[filename_1]&board=$board&id=$data_array[id]'>$data_array[filename_1] ($data_array[filesize_1]byte)</a>";