안녕하세요.
문의폼 완료페이지 이동시 ppt파일은 문제없이 잘 다운로드 되는데
pdf파일은 pdf 경로로 이동이되네요ㅠ
문의폼 완료페이지 이동시 즉시, PDF 파일을 다운로드 할수있을까요?
도움 부탁드립니다!! ㅠㅠ
Copy
$(document).ready(function(){
download();
});
function download(){
location.href = "/download/test.pptx"; //문제없음
location.href = "/download/test.pdt"; //다운로드 되지않고 링크이동됨
}
답변 3개
채택된 답변
+20 포인트
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 "해당 파일이 없습니다.";
}
?>
답변을 작성하려면 로그인이 필요합니다.