Reputation: 809
I am trying to make make a visitor download text file when visiting a certain page. This is the page:
<?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)
?>
However, the file just shows up in the browser, in stead of asking for downloading. What am i doing wrong?
Upvotes: 0
Views: 1424
Reputation: 1361
You might be missing some header properties.
<?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;
?>
Upvotes: 1