preg_replace 和 file_get_contents 不读取阿拉伯文文件名

preg_replace and file_get_contents not reading Arabic file names

首先是 preg_replace 没有读取文件名的阿拉伯字符,因此在下载时它只显示 .pdf,所以我将阿拉伯字符添加到 preg_replace 以按原样获取文件名。现在文件名显示为“اÙÙÙاعداÙعربÙ​​ŠØ©.pdf”

我不确定我的代码是否有问题

public function download($id){
    $toReturn = study_material::where('id',$id)->first();
    if(file_exists('uploads/material/'.$toReturn->material_file)){
        $fileName = preg_replace('/[^أ-يa-zA-Z0-9-_\.]/','',$toReturn->material_title). "." .pathinfo($toReturn->material_file, PATHINFO_EXTENSION);
        header("Content-Type: application/force-download");
        header('Content-Type: text/html; charset=utf-8');
        header("Content-Disposition: attachment; filename=" . $fileName);
        echo file_get_contents('uploads/material/'.$toReturn->material_file);
    }
    exit;
}

preg_replace 不支持多字节字符串,因此函数将多字节字母理解为单独的字母。您将需要使用多字节兼容函数,例如 mb_ereg_replace.