새창에서 안열리고 이미지 다운로드 됨
downTest.html
<a href="fileDown.php?filename=testimg01&Imgurl=이미지URL">Download</a>
======================================================================
fileDown.php
<?php
$filename = $_REQUEST['filename'];
$save_dir = $_REQUEST['Imgurl'];
/*
Header("Content-type: application/x-msdownload");
Header("Content-Disposition: attachment; filename=".$filename.".png");
Header("Content-Transfer-Encoding: binary");
Header("Pragma: no-cache");
Header("Expires: 0");
$handle = fopen($save_dir, "r");
while(!feof($handle)){
echo fread($handle,4096);
};
*/
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($filename));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($save_dir));
ob_clean();
flush();
readfile($save_dir);
exit;
?>
'PHP' 카테고리의 다른 글
[PHP] PHPExcel 을 이용한 엑셀 업로드 후 내용 불러오기 (0) | 2017.09.19 |
---|---|
[PHP] php에서 파일 생성 및 수정하기 (0) | 2017.08.25 |
[PHP] Date 함수 (0) | 2017.08.14 |
[PHP] str_replace (0) | 2017.08.14 |
[PHP] 반복문(while, do..while, for) (0) | 2017.07.17 |