First it was the preg_replace not reading Arabic characters for file name so when downloading it shows .pdf only so I added the arabic characters to the preg_replace to get the file name as is. Now the file name shows as "اÙÙÙاعداÙعربية.pdf"
I'm not sure if anything wrong with my code
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;
}