PHP清理文件名(韩语)和强制下载

时间:2018-06-06 13:11:45

标签: php download http-headers sanitization force-download

有我的消毒功能。

function sanitize($string, $forceLowercase = false, $anal = false, $limitFilename = 128)
{
    $strip = array("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "=", "+", "[", "{", "]",
        "}", "\\", "|", ";", ":", "\"", "'", "‘", "’", "“", "”", "–", "—",
        "—", "–", ",", "<", ".", ">", "/", "?");
    $clean = trim(str_replace($strip, "", strip_tags($string)));
    $clean = preg_replace('/\s+/', "-", $clean);
    $clean = ($anal) ? preg_replace("/[^a-zA-Z0-9]/", "", $clean) : $clean;
    $clean = ($forceLowercase) ?
        (function_exists('mb_strtolower')) ?
            mb_strtolower($clean, 'UTF-8') :
            strtolower($clean) :
        $clean;
    $specialChars = "\x00\x21\x22\x24\x25\x2a\x2f\x3a\x3c\x3e\x3f\x5c\x7c";
    $clean = str_replace(str_split($specialChars), '_', $clean);
    $clean = substr($clean, 0, $limitFilename);
    $clean = mb_convert_encoding($clean, 'UTF-8', 'UTF-8');
    $clean = html_entity_decode($clean);
    return $clean;
}

我发送文件名,此标题的工作原理为英文字符串。

header('Content-Disposition: attachment; filename="' . sanitize($string) . '.3gp"');

但不使用此字符串

  

(자막)2018브리튼즈갓탤런트 - 마크스펠만“'진짜마술'은이런것”(Britan's Got Talent - Marc Spelmann)골든부저

我收到此错误。

  

AH02430:响应标题'Content-Disposition'值'附件;文件名=“\ XEC \ x9e \ X90 \ XEB \ XA7 \ x89-2018- \ XEB \ XB8 \ x8c \ XEB \ xa6 \ XAC \固定的\ x8a \ XBC \ XEC \ xa6 \ x88- \ XEA \ XB0 \ x93- \固定的\ X83 \ XA4 \ XEB \ x9f \ XB0 \固定的\ x8a \ XB8 --- \ XEB \ XA7 \ X88 \固定的\ X81 \ xac- \ XEC \ x8a \ XA4 \固定的\ x8e \ XA0 \ XEB \ XA7 \ x8c- \ XEC \ XA7 \ X84 \ XEC \ XA7 \ x9c- \ XEB \ XA7 \ X88 \ XEC \ X88 \ XA0 \ BM ?? \ b 13 \ xc8 \ x88- \×10 -6 \ X18 ??? \ x11 ?? \ b \ x15 \ x18 \ x19?\ bH \ x13X ?? \ x14?\ x19 \ x1bX ?? H ??????。3gp“'包含无效字符,中止请求

我哪里错了?

0 个答案:

没有答案