【问题标题】:PHP, Changing download filenamePHP,更改下载文件名
【发布时间】:2015-02-24 00:11:13
【问题描述】:

我有一个 PHP 代码,用户可以在其中下载 CSV 文件:

header( 'Content-Type: text/csv' );
$file = fopen( 'php://output', 'w' );
//-- Write stuff
fclose($file);

通常,浏览器开始将内容下载到文件中。但它会始终使用名称“csv.csv”保存下载的文件。有没有办法更改这个默认名称?

例如,在上一页中,我可以询问用户他/她想要哪个名称。

【问题讨论】:

    标签: php csv http-headers webclient


    【解决方案1】:

    你需要设置 Content-Disposition 标头:

    header('Content-Disposition: attachment; filename="file.csv"');
    

    header('Content-Disposition: filename="file.csv"');
    

    header('Content-Disposition: filename="' . $filename . '"');
    

    【讨论】:

    • 应该很简单!谢谢! =)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-01
    • 2011-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多