請問各位
以下是我從網路上找到的標準範例,
不知哪邊錯誤,我的頁面都無法成功下載檔案呢。
PS. 確定檔案有產生
$handle = fopen("file.txt", "w");
fwrite($handle, "text1.....");
fclose($handle);
$url = "http://localhost/file.txt";
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename('file.txt'));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize('file.txt'));
readfile('file.txt');
exit;