무조건 다운로드 받게 하는 소스에 관한 문의 정보
무조건 다운로드 받게 하는 소스에 관한 문의본문
파일 확장자명에 상관없이 무조건 다운로드 받게 하는 소스에 관한 질문입니다.
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);
}
?>
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>
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>
정말 감사합니다.
적용해보니 너무 잘됩니다.
이틀을 고민했던 것인데, 가르쳐주신대로 하니 잘 됩니다.
감사합니다.
적용해보니 너무 잘됩니다.
이틀을 고민했던 것인데, 가르쳐주신대로 하니 잘 됩니다.
감사합니다.
감사합니다.