Solved

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

Posted on 2014-10-29
4
103 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 83

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

776 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