문의폼 완료 pdf 다운로드 채택완료
gnuxboard
3년 전
조회 2,451
안녕하세요.
문의폼 완료페이지 이동시 ppt파일은 문제없이 잘 다운로드 되는데
pdf파일은 pdf 경로로 이동이되네요ㅠ
문의폼 완료페이지 이동시 즉시, PDF 파일을 다운로드 할수있을까요?
도움 부탁드립니다!! ㅠㅠ
</p>
<p>$(document).ready(function(){</p>
<p> download();</p>
<p> });</p>
<p> </p>
<p> function download(){</p>
<p> location.href = "/download/test.pptx"; //문제없음</p>
<p> location.href = "/download/test.pdt"; //다운로드 되지않고 링크이동됨</p>
<p> }</p>
<p>
댓글을 작성하려면 로그인이 필요합니다.
답변 3개
채택된 답변
+20 포인트
3년 전
location.href = "/download.php?file=test.pdf&target_Dir=/download/";
- download.php -
<?
$filename = $_GET["file"];
$target_Dir = $_GET["target_Dir"];
$file = $_SERVER['DOCUMENT_ROOT']."/".$target_Dir."/".$filename;
$filesize = filesize($file);
if (is_file($file)) {
header("Content-type: application/octet-stream");
header("Content-Length: ".filesize("$file"));
header("Content-Disposition: attachment; filename=$filename"); // 다운로드되는 파일명 (실제 파일명과 별개로 지정 가능)
header("Content-Transfer-Encoding: binary");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
header("Expires: 0");
/*
if (preg_match("MSIE", $_SERVER['HTTP_USER_AGENT'])) {
header("Content-type: application/octet-stream");
header("Content-Length: ".filesize("$file"));
header("Content-Disposition: attachment; filename=$filename"); // 다운로드되는 파일명 (실제 파일명과 별개로 지정 가능)
header("Content-Transfer-Encoding: binary");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
header("Expires: 0");
}else {
header("Content-type: file/unknown");
header("Content-Length: ".filesize("$file"));
header("Content-Disposition: attachment; filename=$filename"); // 다운로드되는 파일명 (실제 파일명과 별개로 지정 가능)
header("Content-Description: PHP3 Generated Data");
header("Pragma: no-cache");
header("Expires: 0");
}
*/
$fp = fopen($file, "rb");
fpassthru($fp);
fclose($fp);
}
else {
echo "해당 파일이 없습니다.";
}
?>
로그인 후 평가할 수 있습니다
댓글을 작성하려면 로그인이 필요합니다.
3년 전
화면에 출력하는것이 아니고 내 피시로 다운 로드하시려면 반드시 해당 해더가 추가 되어야 다운로드 됩니다.
Header("Content-type:application/octet-stream");
Header("Content-Disposition:attachment; filename=".$filename);
요런식으로 해당 해더를 상단에 파일명과 함께 넣어보시기 바랍니다.
로그인 후 평가할 수 있습니다
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인