[php] 다운로드시 파일이름을 바꿔서 받게 만드는 것..

tinywolf의 이미지

어딘가에서 주워서 아래와 같이 했습니다.

일단 불여우에선 잘 돌아갑니다.. 만!

MS IE 6에선 도무지 바뀐 파일이름이 안오고 이상하게 깨진 문자들만...

한글 파일 이름들만 그런 것으로 보아서 혹시 인코딩 문제일까요?

전반적으로 utf8을 사용하는데..

과연 어떤 인코딩으로 찔러줘야 하는 것일까.. 난감하기만 합니다..

			if (eregi("(MSIE 5.0|MSIE 5.1|MSIE 5.5|MSIE 6.0)", $HTTP_USER_AGENT))
			{
				header("Content-type: application/octet-stream");
				header("Content-Length: ".filesize("../data/".$file_code));
				header("Content-Disposition: attachment; filename=\"".$file_name."\"");
				header("Content-Transfer-Encoding: binary");
				header("Pragma: public");
				header("Expires: 0");
			}
			else
			{
				header("Content-type: file/unknown");
				header("Content-Length: ".filesize("../data/".$file_code));
				header("Content-Disposition: attachment; filename=\"".$file_name."\"");
				header("Content-Description: File Transfer");
				header("Pragma: public");
				header("Expires: 0");
			} 
			readfile("../data/" . $file_code);
차리서의 이미지

tinywolf wrote:
어딘가에서 주워서 아래와 같이 했습니다.
일단 불여우에선 잘 돌아갑니다.. 만!
MS IE 6에선 도무지 바뀐 파일이름이 안오고 이상하게 깨진 문자들만...
한글 파일 이름들만 그런 것으로 보아서 혹시 인코딩 문제일까요?
전반적으로 utf8을 사용하는데..
과연 어떤 인코딩으로 찔러줘야 하는 것일까.. 난감하기만 합니다..
			if (eregi("(MSIE 5.0|MSIE 5.1|MSIE 5.5|MSIE 6.0)", $HTTP_USER_AGENT))
			{
				header("Content-type: application/octet-stream");
				header("Content-Length: ".filesize("../data/".$file_code));
				header("Content-Disposition: attachment; filename=\"".$file_name."\"");
				header("Content-Transfer-Encoding: binary");
				header("Pragma: public");
				header("Expires: 0");
			}
			else
			{
				header("Content-type: file/unknown");
				header("Content-Length: ".filesize("../data/".$file_code));
				header("Content-Disposition: attachment; filename=\"".$file_name."\"");
				header("Content-Description: File Transfer");
				header("Pragma: public");
				header("Expires: 0");
			} 
			readfile("../data/" . $file_code);

다음과 같이 iconv로 변환해보시면 어떨까요? 예전에 이런 식으로 변환해서 MS IE에서도 잘 작동했던 기억이 있습니다.
if (eregi("MSIE [56]", $_SERVER["HTTP_USER_AGENT"])) {
        header("Content-type: application/octet-stream");
        header("Content-Length: " . filesize("../data/" . $file_code));
        header("Content-Disposition: attachment; filename=\""
                . iconv("UTF-8", "EUC-KR", $file_name) . "\"");
        header("Content-Transfer-Encoding: binary");
} else {
        header("Content-type: file/unknown");
        header("Content-Length: " . filesize("../data/" . $file_code));
        header("Content-Disposition: attachment; filename=\""
                . $file_name . "\"");
        header("Content-Description: File Transfer");
} 
header("Pragma: public");
header("Expires: 0");

(코드 일부를 바꾸었습니다. 브라우저 정보가 들어있는 변수는 $_SERVER 배열에서 참조하는게 좋습니다. 정규표현식은 조금 더 큰 언어를 표현하는 간단한 식으로 바꾸어보았습니다.)

--
자본주의, 자유민주주의 사회에서는 결국 자유마저 돈으로 사야하나보다.
사줄테니 제발 팔기나 해다오. 아직 내가 "사겠다"고 말하는 동안에 말이다!

tinywolf의 이미지

수정 감사합니다.
iconv는 utf8에서 euc-kr로 이미 한번 시도해 보았었는데 안되더군요..
그래도 코드는 다시 잘라서 붙여 넣기넣기~

ㅡ_ㅡ;

tinywolf의 이미지

이런 죄송합니다..
방금 이 코드 붙여넣고 해보니 잘됩니다! (감동 주룩)
음.. iconv를 제가 잘못 사용했었나 봅니다..

감사합니다!

ㅡ_ㅡ;

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.