Unfortunately, there is currently no solution that works with all browsers. There are at least three “more obvious” approaches to this issue.
a) Content-type: application/octet-stream; charset=utf-8+ filename=<utf8 byte sequence>
for example filename=.txt
This is a violation of the standards, but firefox shows the name correctly. IE does not.
b) Content-type: application/octet-stream; charset=utf-8+ filename=<urlencode(utf8 byte sequence)>
for example filename=%D0%9C%D0%BE%D1%81%D0%BA%D0%B2%D0%B0.txt
This works with IE, but not firefox.
c) providing the name specified in rfc 2231
for example, filename*=UTF-8''%D0%9C%D0%BE%D1%81%D0%BA%D0%B2%D0%B0.txt
Firefox again supports this, IE does not.
for a more complete comparison see http://greenbytes.de/tech/tc2231/
edit: , , header ('...'). - .
filename = xyz, URL-. <a href="test.php/lala.txt"> firefox, IE lalala.txt .
php script ( apache httpd . http://httpd.apache.org/docs/2.1/mod/core.html#acceptpathinfo).
. test.php http://localhost/test.php/x/y/z, $_SERVER['PATH_INFO'] /x/y/z.
, ,
<a
href="/test.php/download/moskwa/Москва"
>
Москва
</a>
download/moskwa/... . - filename =... Firefox IE "" .
rfc 2231. moskwa . , script , . IE filename*=... - URL-, . , firefox ( , rfc 2231) id *, IE ( , rfc 2231) .
:
<?php
$files = array(
'moskwa'=>array(
'htmlentities'=>'Москва',
'content'=>'55° 45′ N, 37° 37′ O'
),
'athen'=>array(
'htmlentities'=>'Αθήνα',
'content'=>'37° 59′ N, 23° 44′ O'
)
);
$fileid = null;
if ( isset($_SERVER['PATH_INFO']) && preg_match('!^/download/([^/]+)!', $_SERVER['PATH_INFO'], $m) ) {
$fileid = $m[1];
}
if ( is_null($fileid) ) {
foreach($files as $fileid=>$bar) {
printf(
'<a href="./test.php/download/%s/%s.txt">%s</a><br />',
$fileid, $bar['htmlentities'], $bar['htmlentities']
);
}
}
else if ( !isset($files[$fileid]) ) {
echo 'no such file';
}
else {
$f = $files[$fileid];
$utf8name = mb_convert_encoding($f['htmlentities'], 'utf-8', 'HTML-ENTITIES');
$utf8name = urlencode($utf8name);
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename*=UTF-8''$utf8name.txt");
header("Content-length: " . strlen($f['content']));
echo $f['content'];
}
*) .
http://stackoverflow.com/questions/2578349/while-downloading-filenames-from-non-english-languages-are-not-getting-displayed
http:
id 2578349