Welcome Guest, Not a member yet? Register   Sign In
Downloading File from Server with force_download

OK, maybe it's because it is so late, but I can't seem to create what I am trying to do.

I'm generating a CSV file that gets held on my server, no problem.

In the view that loads I want a link that forces the file to download with out redirecting the screen that I am on - from a UI perspective I click the link and the download starts. I can use anchor_popup linking to the controller that has the force_download in it, which opens a small popup window and the file begins downloading, from a UI perspective I am fine with this.

I would like to include a message in the popup window about the file being downloaded, etc. Unfortunately I can't write any content into the popup window - I think the download headers are stopping that from happening.

Here is my code:

Link in view:
<?php echo anchor_popup('subject_search/downloadcsv', 'Download CSV of Results', $popupatts);?>

function downloadcsv()
$data = file_get_contents("./downloads/searchresults.csv");
$name = 'searchresults.csv';
force_download($name, $data);    

Is there a better way I should be trying to do this? What am I missing?

Theme © iAndrew 2016 - Forum software by © MyBB