• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 121
  • Last Modified:

Can I make this into a link as opposed to a forced download?

I've made my CSV file and it is pristine, but rather than this:

$filename="results.csv";
header('Content-type:application/csv');
header('Content-Disposition: attachment; filename='.$filename);
echo $output;

I want to make "results.csv" a link as opposed to a forced download.

How?
0
brucegust
Asked:
brucegust
2 Solutions
 
Chris WatsonSoftware DeveloperCommented:
Remove this line.

header('Content-Disposition: attachment; filename='.$filename);

Open in new window

0
 
S. Rahul BoseCommented:
Since the header has been set and it is echoed right at the beginning, you cannot add a link later on in the script.  This is because the server has already told your browser that a csv is going to arrive and not html.  Since link is part of html, your intended purpose cannot be achieved.

Instead, you could have a process_results.php file which contains the code you mentioned, and link process_results.php, which in turn will let your users to download results.csv.
0
 
Dave BaldwinFixer of ProblemsCommented:
Making it a 'link' means it will display in the browser.  That is not a good way to download it especially if it is a large file.
0
 
brucegustPHP DeveloperAuthor Commented:
I kind of figured I as barking up the wrong tree, but wanted to have it confirmed so I wasn't wasting time.

Thanks!
1

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now