Reputation: 4869
I have a Codeigniter function which puts some data in a file to be downloaded.
$data= "test";
header('Content-Disposition: attachment; filename=test.file');
echo $data;
However, the content includes the HTML for that view in which I click on to activate the function as well. How do I remove the content for the HTML inside the file?
Upvotes: 2
Views: 206
Reputation: 775
Create a method in a controller
sample code:
public function download_file($name)
{
$data = file_get_contents(FCPATH . 'storage' . DIRECTORY_SEPARATOR. $name); // Read the file's contents
force_download($name, $data);
redirect('index/index');
}
Call the above method from view page
Upvotes: 0