[英]Force download file with Joomla 3
我試圖在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具有“讀取權限”。
我在一個隔離的文件中測試了代碼,並且工作正常。
在此先感謝大家。
添加:
ob_clean();
flush();
在readfile ($ file)解決我的問題之前。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.