du060334 2016-11-30 23:39
浏览 76
已采纳

preg_replace和file_get_contents没有读取阿拉伯文件名

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;
}
  • 写回答

1条回答 默认 最新

  • dongxian3418 2016-12-01 20:59
    关注

    preg_replace does not support multibyte strings, so multi-byte letters are understood by the function as separate letters. You will need to use a multi-byte compatible function like mb_ereg_replace.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?