본문 바로가기

Web Progreming/PHP

[ PHP ] 파일 다운로드


if(eregi("(MSIE 5.5|MSIE 6.0|MSIE 8.0|MSIE 7.0)", $HTTP_USER_AGENT)) // 브라우져 구분
{
Header("Content-type: application/octet-stream");
Header("Content-Length: ".filesize("$download_file"));   // 이부분을 넣어 주어야지 다운로드 진행 상태가 표시 됩니다.
Header("Content-Disposition: attachment; filename=$save_file");
Header("Content-Transfer-Encoding: binary");
Header("Pragma: no-cache");
Header("Expires: 0");
} else {
Header("Content-type: file/unknown");
// Header("Content-type: application/octet-stream");
Header("Content-Length: ".filesize("$filename"));
Header("Content-Disposition: attachment; filename=$file_name");
Header("Content-Description: PHP3 Generated Data");
Header("Pragma: no-cache");
Header("Expires: 0");
}

if(is_file($download_file)){
$fp=fopen($download_file,"rb");
if (!fpassthru($fp)){
fclose($fp);
echo "
<script>
location.reload();
</script>";
}
}else{
echo "
<script>
alert('파일 다운로드 과정에서 오류가 발생하였습니다.다시 시도해 주십시오.');
location.reload();
</script>";
}