rfc2231

How can I encode a filename according to RFC 2231?

元气小坏坏 提交于 2019-12-10 21:33:02
问题 I need to encode file attachments at the Content-Disposition HTTP header attribute. I noticed that RFC 2231 is the latest widely-accepted standard and would like to use that. However, I have trouble finding an implementation of that within the core Java SE and Java EE libraries. Do you guys have any recommendations? A brief search on Google yielded this but I ain't sure how trustworthy it is. I was hopping javax.mail.internet.MimeUtility supports RFC 2231 encoding method but it does not

How can I encode a filename in PHP according to RFC 2231?

和自甴很熟 提交于 2019-11-28 14:00:50
How can I encode the value of a filename according to the encoding of MIME Parameter Value and Encoded Word Extensions: Character Sets, Languages, and Continuations (RFC 2231) ? I think this should do it: function rfc2231_encode($name, $value, $charset='', $lang='', $ll=78) { if (strlen($name) === 0 || preg_match('/[\x00-\x20*\'%()<>@,;:\\\\"\/[\]?=\x80-\xFF]/', $name)) { // invalid parameter name; return false; } if (strlen($charset) !== 0 && !preg_match('/^[A-Za-z]{1,8}(?:-[A-Za-z]{1,8})*$/', $charset)) { // invalid charset; return false; } if (strlen($lang) !== 0 && !preg_match('/^[A-Za-z]

PHP: RFC-2231 How to encode UTF-8 String as Content-Disposition filename

末鹿安然 提交于 2019-11-28 08:29:51
问题 Scenario: (in PHP) I have a form submission with a UTF-8 encoded string ( $name ) to support international characters. Upon submitting the form (via GET), I am creating a CSV download file. I want the name of the file to be that string + .csv ( "$name.csv" ). For a western character set I can do this just fine by doing: header("Content-Disposition: attachment; filename=\"$name\""); But for other character sets, the download file's name is garbage letters + .csv (such as ×œ×œ× ×›×•×ª×¨×ª.csv )

How can I encode a filename in PHP according to RFC 2231?

耗尽温柔 提交于 2019-11-27 08:04:09
问题 How can I encode the value of a filename according to the encoding of MIME Parameter Value and Encoded Word Extensions: Character Sets, Languages, and Continuations (RFC 2231)? 回答1: I think this should do it: function rfc2231_encode($name, $value, $charset='', $lang='', $ll=78) { if (strlen($name) === 0 || preg_match('/[\x00-\x20*\'%()<>@,;:\\\\"\/[\]?=\x80-\xFF]/', $name)) { // invalid parameter name; return false; } if (strlen($charset) !== 0 && !preg_match('/^[A-Za-z]{1,8}(?:-[A-Za-z]{1,8}