2016-11-30 101 views
0

首先,它是沒有的preg_replace讀阿拉伯語字符的文件名,所以當下載它顯示.PDF只讓我增加了阿拉伯語字符preg_replace函數來獲取文件名是。現在,文件名顯示爲「اÙÙÙاعداÙعربÙ​​ŠØ©.PDF」的preg_replace和的file_get_contents不讀阿拉伯語文件名

我不知道如果有什麼錯我的代碼

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; 
} 

回答

1

的preg_replace不支持多字節字符串,因此函數將多字節字母理解爲單獨的字母。您將需要使用像mb_ereg_replace這樣的多字節兼容功能。

+0

所以你的意思是我用'mb_ereg_replace'替換'preg_replace'這會解決這個問題嗎?或需要進一步的步驟? –

+0

我相信它應該解決這個問題。 – Sarmad