【问题标题】:Force download file with Joomla 3使用 Joomla 3 强制下载文件
【发布时间】:2015-02-10 01:44:12
【问题描述】:

我正在尝试在 Joomla 3 的自定义组件中强制下载文件。我的控制器的操作具有以下代码:

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 );
exit();

$file 是文件的绝对路径,Apache 有“读取权限”。

我在一个独立的文件中测试了代码,它运行良好。

提前谢谢各位。

【问题讨论】:

    标签: php joomla components readfile


    【解决方案1】:

    添加:

    ob_clean(); 
    flush();
    

    readfile($file) 解决我的问题之前。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-16
      • 2010-11-03
      • 2010-11-30
      • 2010-10-31
      相关资源
      最近更新 更多