Php Laravel 5.7存储下载CSV文件添加了.txt扩展名

Php Laravel 5.7存储下载CSV文件添加了.txt扩展名,php,laravel,csv,Php,Laravel,Csv,在Laravel5.7中,我使用了一个简单的路径,允许用户下载本地存储的csv文件 Route::get('download/{file}', function($file) { return Storage::disk('s3')->download($file, $file, ['Content-Type: text/csv"']); })->name('download'); 在我的刀片模板中: <a href="{{ Ro

在Laravel5.7中,我使用了一个简单的路径,允许用户下载本地存储的csv文件

Route::get('download/{file}', function($file) {
            return Storage::disk('s3')->download($file, $file, ['Content-Type: text/csv"']);
           })->name('download');
在我的刀片模板中:

<a href="{{ Route('download', ['file' => 'import.csv']) }}" class="btn btn-primary btn-sm btn-line btn-rect" data-original-title="" title=""> <i class="fa fa-download" aria-hidden="true"></i>
EDIT2:我添加了一个带有控制器的新测试。 路线:

控制器
测试

public function test()
{
  return Storage::disk('public')->download('import.csv', 'import.csv', ['Content-Type: text/csv"','Content-disposition: attachment;filename=MyVerySpecial.csv']);
}
完全相同的结果

EDIT3:使用标题进行测试:

['Content-Type: application/octet-stream"','Content-disposition: attachment;filename="MyVerySpecial.csv"']
同样的结果

EDIT4:看起来是服务器配置问题,因为我在Firefox(最新开发版本)上遇到了这个问题,而在IE上没有

谢谢你的帮助

EDIT5:我认为Laravel有问题,因为如果我使用以下内容创建php文件:

<?php
$file = "../storage/app/public/import.csv";
header("Content-Description: File Transfer");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . basename($file));
readfile ($file);
exit();    
嗯,它不起作用


问题:是否有其他人试图复制相同的问题?

您必须添加所有这些标题:

header('Content-type: application/octet-stream');
header('Content-Length: ' . filesize($data));
header('Content-Disposition: attachment; filename="export.csv"');
Route::get('/', function () {
    return Storage::disk('public')->download('import.csv', 'import.csv', ['Content-Description' =>  'File Transfer','Content-Type' => 'application/octet-stream','Content-Disposition' => 'attachment; filename=import.csv']);
});

此问题的答案是用于标题的格式:

header('Content-type: application/octet-stream');
header('Content-Length: ' . filesize($data));
header('Content-Disposition: attachment; filename="export.csv"');
Route::get('/', function () {
    return Storage::disk('public')->download('import.csv', 'import.csv', ['Content-Description' =>  'File Transfer','Content-Type' => 'application/octet-stream','Content-Disposition' => 'attachment; filename=import.csv']);
});

这是在Firefox、IE和Chrome上测试的一种向下载文件发送标题的好方法。您是否检查过:是的,仍然存在相同的问题。请注意,我不想使用控制器,我只想使用路由功能(我将使用控制器进行测试,我刚刚安装了一个全新的Laravel 5.7和相同的错误),您可以在浏览器中检查响应标题吗?特别是
Content-Type
response头:0 Content-Type:application/octet-stream“1 Content-disposition:attachment;filename=“MyVerySpecial.csv”运行
apache2-M
并检查
mime\u模块是否已加载,是否可以在其他机器或浏览器中测试下载?我已经添加了这些头(不是内容长度,因为我在访问路由时没有文件对象),相同的结果(请参见我的编辑)尝试按照文档中的解释:因此,获取文件路径,然后
return-response()->下载($pathToFile);
return-response()->下载('storage/import.csv',import.csv',['Content-Type:application/octet-stream','Content-disposition:attachment;filename=“MyVerySpecial.csv”];
Route::get('/', function () {
    return Storage::disk('public')->download('import.csv', 'import.csv', ['Content-Description' =>  'File Transfer','Content-Type' => 'application/octet-stream','Content-Disposition' => 'attachment; filename=import.csv']);
});