下载图片调用downlaod方法在safari中中文名是乱码,代码和错误截图如下, 通过设置请求头Content-type:text/html;charset=utf-8能解决不 return response()->download(base_path() . '/resource/' . $id . '.jpg', 'avatar.jpg');
不要直接用downlaod方法,构造一下header信息,贴一段我目前的下载
$sourceName = '某某某.mp4'; $encoded_filename = urlencode($sourceName); $encoded_filename = str_replace("+", "%20", $encoded_filename); $encodefilename = rawurlencode($sourceName); $user_agent = strtolower($request->header('user-agent')); $filepath = '/data/xxx.mp4'; if (file_exists($filepath)) { $respone = response(); $respone->withFile($filepath); if (preg_match("/msie|edge/", $user_agent)) { $respone->header('Content-Disposition', "attachment; filename=\"$encoded_filename\""); } elseif (preg_match("/safari/", $user_agent)) { $respone->header('Content-Disposition', "attachment; filename=\"$sourceName\""); } else { $respone->header('Content-Disposition', "attachment; filename=\"$sourceName\"; filename*=utf-8\"$encodefilename\""); } return $respone; } else { throw new Exception('文件不存在,下载文件失败'); }
感谢大神解答
不要直接用downlaod方法,构造一下header信息,贴一段我目前的下载
感谢大神解答