laravel在下载的文件中添加.txt [英] laravel adding .txt on the downloaded file

查看:155
本文介绍了laravel在下载的文件中添加.txt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图给用户下载特定文件的能力。这是我的代码。

im trying to give the user ability to download a specific file. here is my code.

但是,在我下载的文件下载之后,它会继续添加.txt。我想要的是.csv

but it keeps adding .txt after the file is downloaded which I want is a .csv

public function downloadCSVSample()
    {

        $file= public_path(). "/downloads/SampleCSV.csv";
        $headers = array(
              'Content-Type: application/csv',
            );
        return Response::download($file, 'SampleCSV.csv', $headers);

    }


推荐答案

很确定您的浏览器无法解释该文件。根据这个解决方案,您需要强制它打开保存as ...'对话框:

I'm pretty sure that your browser can't interpret the file. According to this solution, you need to force it to open 'save as...' dialog:

$headers = array(
          'Content-Type: text/csv',
          'Content-disposition: attachment'
);

这篇关于laravel在下载的文件中添加.txt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆