download.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?
  2. include $_SERVER['DOCUMENT_ROOT']."/common/lib/define.php";
  3. $local_dir = $_SERVER['DOCUMENT_ROOT'].UPLOAD_PATH;
  4. // local file that should be send to the client
  5. $local_file = urldecode($_GET['nm_file']);
  6. $cd_board = urldecode($_GET['cd_board']);
  7. $type = urldecode($_GET['type']);
  8. //이부분은 항상 필터링 해야함
  9. if($type=="job"){
  10. $filename = $local_dir."job/".$local_file;
  11. }else{
  12. $filename = $local_dir."board/board_".$cd_board."/".$local_file;
  13. }
  14. // set the download rate limit (=> 20,5 kb/s)
  15. $download_rate =100;
  16. // $filename 내에 저장된 파일 풀 경로를 가지고 있다고 가정
  17. if (!is_file($filename)) {
  18. die('File Is Empty!!');
  19. }
  20. $filepath = str_replace('\\', '/', realpath($filename));
  21. $filesize = filesize($filepath);
  22. $filename = substr(strrchr('/'.$filepath, '/'), 1);
  23. $extension = strtolower(substr(strrchr($filepath, '.'), 1));
  24. //IE인가 HTTP_USER_AGENT로 확인
  25. $ie= isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false;
  26. //IE인경우 한글파일명이 깨지는 경우를 방지하기 위한 코드
  27. if( $ie ){
  28. $filename = iconv('utf-8', 'euc-kr', $filename);
  29. }
  30. //기본 헤더 적용
  31. $mime = array('application/octet-stream');
  32. header( "Content-type: application/vnd.ms-excel;charset=UTF-8");
  33. header('Content-Type: '.$mime);
  34. header('Content-Disposition: attachment; filename="'.iconv('UTF-8','CP949',$filename).'"');
  35. header('Content-Transfer-Encoding: binary');
  36. header('Content-Length: '.sprintf('%d', $filesize));
  37. header('Expires: 0');
  38. // IE를 위한 헤더 적용
  39. if( $ie ){
  40. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  41. header('Pragma: public');
  42. } else {
  43. header('Pragma: no-cache');
  44. }
  45. //해당 파일을 binary로 읽어와 출력
  46. $handle = fopen($filepath, 'rb');
  47. fpassthru($handle);
  48. fclose($handle);
  49. ?>