Page 1 of 1

HTTP-header fails on 8-bit characters in Mozilla 1.4

Posted: Fri Apr 25, 2003 6:08 pm
by Heavy

Code: Select all

header("Content-type: application/msword");
header('Content-Disposition: attachment; filename=skåp.doc');
The above headers are sent to force a "Save As..." popup dialog for download of a document kalled skåp.doc, with content of which is to be output by PHP.

It works if the filename is "skap.doc" but doesn't when the filename is "skåp.doc".

This is a problem related primarily to Mozilla, but the problem is, the developers of Mozilla turned my bug report down and said that my application was out of specification, since å is an 8-bit character.

Here is the message I got:
Not a bug; your Content-Disposition header is out of spec. Non us-ascii strings
must use MIME parameter-value encoding. See RFC 2231
and here is where my mozilla bug report discussion is:
http://bugzilla.mozilla.org/show_bug.cgi?id=65827#c75
The symptom is:
Instead of the suggested file name "skåp.doc", the browser presents the SCRIPTS file name in the "Save As..." dialog, which is not very good. It works fine in all other situations BUT when 8-bit characters go along with the filename.

So, silly me tries something like

Code: Select all

header("Content-type: application/msword");
header('Content-Disposition: attachment; filename="=?iso-8859-1?Q?sk=E5p.doc?="');
This does not work in any of the browsers I have installed, so now I am even more out of specification 8O.
I will continue trying, but would be happy for any helping hands.

Posted: Wed Oct 22, 2003 9:34 am
by default101
...filename="=?iso-8859-1?Q?sk=E5p.doc?="' ...
This is also depreciated, you should use encoding according to RFC 2231, I filed a bug in mozilla on this behavior (http://bugzilla.mozilla.org/show_bug.cgi?id=221028) and i did it like this:

Code: Select all

$disp_file = "*="iso-8859-1'de'"
                    . str_replace(
                            array(" ",  "Ä",  "ä",  "Ö",  "ö",  "Ü",  "ü",  "ß"  ),
                            array("%20","%C4","%E4","%D6","%F6","%DC","%FC","%DF"),
                            basename($file)
                        ).""";
    header( 'Content-Type: ' . $ct );
    header( 'Content-Disposition: attachment; filename' . $disp_file  );   
    header( 'Content-Length: ' . $size );
    header( 'Content-Transfer-Encoding: binary' );
    readfile( $file );

Posted: Thu Oct 23, 2003 12:35 am
by volka
array(" ", "Ä", "ä", "Ö", "ö", "Ü", "ü", "ß" ),
array("%20","%C4","%E4","%D6","%F6","%DC","%FC","%DF"),
That's the same table as urlencode() uses?