무조건 다운로드 받게 하는 소스에 관한 문의 > 그누4 질문답변

그누4 질문답변

그누보드4 관련 질문은 QA 로 이전됩니다. QA 그누보드4 바로가기
기존 게시물은 열람만 가능합니다.

무조건 다운로드 받게 하는 소스에 관한 문의 정보

무조건 다운로드 받게 하는 소스에 관한 문의

본문

파일 확장자명에 상관없이 무조건 다운로드 받게 하는 소스에 관한 질문입니다.
http://sir.co.kr/bbs/board.php?bo_table=g4_tiptech&wr_id=15475 의 팁을 적용중입니다.
아래 소스 중 2번째 줄과 3번째 줄에 경로명과 위치를 삽입하라고 하는데, 아무리 해도 잘 모르겠습니다.
현재 파일의 경로는 gnuboard4/inc/doc/a.pdf 입니다.
메인화면에서 배너를 클릭하면 a.pdf가 다운로드 되게끔 하려고 합니다.
부탁드립니다.

<?
$code = "/home/test/www/"; //자신의 경로에 맞게 수정
$file="$code/$filename"; // 화일이 실제로 있는 위치를..
$file_size=filesize($file);

// 브라우저 골라서 헤더를 따로 따로 전송 해 준다.(5.5 일때는 다르게 해줘야 함)
if( strstr($HTTP_USER_AGENT,"MSIE 5.5")){
header("Content-Type: doesn/matter ");
header("Content-Disposition: filename=$filename ");
header("Content-Transfer-Encoding: binary ");
header("Pragma: no-cache");
header("Expires: 0");
}else{

Header("Content-type: file/unknown");
Header("Content-Disposition: attachment; filename=$filename");
Header("Content-Description: PHP3 Generated Data");
header("Pragma: no-cache");
header("Expires: 0");
}
if(is_file("$file")){
$fp = fopen("$file","r");
if (!fpassthru($fp))
fclose($fp);
}

?>

댓글 전체

위의 파일을 그대로 이용하자면 다음과 같이 하시면 될 것 같네요.
1. 먼저 download.php라는 파일을 gnuboard4 가 설치된 폴더에 생성을 하고 내용은 다음으로 합니다:
<?
include_once('./_common.php');

$code = "$g4[path]/inc/doc"; //자신의 경로에 맞게 수정
$file="$code/$filename"; // 화일이 실제로 있는 위치를..
$file_size=filesize($file);

// 브라우저 골라서 헤더를 따로 따로 전송 해 준다.(5.5 일때는 다르게 해줘야 함)
if( strstr($HTTP_USER_AGENT,"MSIE 5.5")){
header("Content-Type: doesn/matter ");
header("Content-Disposition: filename=$filename ");
header("Content-Transfer-Encoding: binary ");
header("Pragma: no-cache");
header("Expires: 0");
}else{

Header("Content-type: file/unknown");
Header("Content-Disposition: attachment; filename=$filename");
Header("Content-Description: PHP3 Generated Data");
header("Pragma: no-cache");
header("Expires: 0");
}
if(is_file("$file")){
$fp = fopen("$file","r");
if (!fpassthru($fp))
fclose($fp);
}

?>

2. download.php 파일을 만드셨으면 이제 gnuboard4/inc/doc/a.pdf파일에 연결을 시켜야 겠죠. 배너의 링크를 걸때 다음으로 걸어줍니다. $g4[url]/download.php?filename=a.pdf

여기서 $g4[url]값은 config.php에서 설정합니다. 제대로 되어 있지 않다면 않되겠죠. 혹은 $g4[path]를 쓰셔도 됩니다.

예: <a href="<?=$g4[url];?>/download.php?filename=a.pdf">[배너....]</a>
전체 66,554 |RSS
그누4 질문답변 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1402호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT