Solved

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

Posted on 2014-10-29
4
93 Views
Last Modified: 2014-10-29
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
Comment
Question by:brucegust
4 Comments
 
LVL 4

Expert Comment

by:Chris Watson
ID: 40411263
Remove this line.

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

Open in new window

0
 

Accepted Solution

by:
S. Rahul Bose earned 250 total points
ID: 40411273
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
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
ID: 40411317
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
 

Author Closing Comment

by:brucegust
ID: 40411435
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Phone Dialer 5 36
while loop in html mail format 5 32
url rewrites not working in codeigniter 2 10
sql sentence 2 12
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now