[英]php force download file not working
我試圖使訪問者在訪問特定頁面時下載文本文件。 這是頁面:
<?php
$file_url = 'text.txt';
header("Content-Disposition: attachment; filename=\"" . basename($file_url) . "\"");
header("Content-Type: application/force-download");
header("Content-Length: " . filesize($file_url));
header("Connection: close");
readfile($file_url)
?>
但是,該文件只是顯示在瀏覽器中,而不是要求下載。 我究竟做錯了什么?
您可能缺少某些標題屬性。
<?php
$file_url = 'text.txt';
header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename='.basename($file_url));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file_url));
readfile($file_url);
exit;
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.