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

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

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

Post 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.
default101
Forum Newbie
Posts: 1
Joined: Wed Oct 22, 2003 9:34 am

Post 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 );
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

array(" ", "Ä", "ä", "Ö", "ö", "Ü", "ü", "ß" ),
array("%20","%C4","%E4","%D6","%F6","%DC","%FC","%DF"),
That's the same table as urlencode() uses?
Post Reply