Solved

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

Posted on 2014-10-29
4
106 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
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.

756 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