【问题标题】:How can I pass multiple file extensions parameter in header?如何在标头中传递多个文件扩展名参数?
【发布时间】:2016-12-13 19:50:58
【问题描述】:

我有不同扩展名的文件,那么如何在一个标题中定义多个扩展名。例如

 header("Content-type: application/xml"); 
 header("Content-type: application/txt");

是否有任何可能性,在单个标题中定义类似这样的内容

 header("Content-type: application/xml txt"); 

提前感谢您的建议

【问题讨论】:

    标签: php file download header-files


    【解决方案1】:

    如果你想下载任何类型的文件,你可以使用application/octet-stream.

    header('Content-Type: application/octet-stream');
    

    // 例如,这将下载任何类型的文件

     header('Content-Description: File Transfer');
     header('Content-Type: application/octet-stream');
     header('Content-Disposition: attachment; filename="' . basename($file) . '"');
     header('Expires: 0');
     header('Cache-Control: must-revalidate');
     header('Pragma: public');
     header('Content-Length: ' . filesize($file));
     readfile($file);
    

    【讨论】:

    • 谢谢,但是否可以在单个标头中定义多个扩展?
    猜你喜欢
    • 2012-09-25
    • 2017-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多