Content-Dispositionヘッダのattachment値を作成
<?php
/**
* Content-Dispositionヘッダの値をタイプによって作成する
* @param $type
* @param $fileName
* @return string
*/
function createContentDisposition($type, $fileName) {
$result = '';
switch($type) {
case 'UTF-8 Raw' :
$result = 'attachment; filename="' . $fileName . '"';
break;
case 'UTF-8 URL Encoded' :
$result = 'attachment; filename="' . rawurlencode($fileName) . '"';
break;
case 'UTF-8 Base64 Encoded' :
$result = 'attachment; filename="=?utf-8?B?' . base64_encode($fileName). '?="';
break;
case 'RFC 5987' :
$result = 'attachment; filename*=UTF-8\'\'' . rawurlencode($fileName);
break;
case 'Shift_JIS Raw' :
$result = 'attachment; filename="' . mb_convert_encoding($fileName, 'Shift_JIS', 'UTF-8') . '"';
break;
case 'Shift_JIS URL Encoded' :
$result = 'attachment; filename="' . rawurlencode(mb_convert_encoding($fileName, 'Shift_JIS', 'UTF-8')) . '"';
break;
}
return $result;
}