0

Been twisting and turning on this for hours now, can't figure out how to make some sense of it.

I'm working in a php file round 6000 rows...

There's multiple header() calls before my switch case header call is executed.

The header() call works if I use ob_start(); and ob_end_flush(); at the top and the bottom of the document.

For some reason I don't understand, this:

$csv = urldecode($source['csv']);
$filename = urldecode($source['file']);     

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");   

print $csv;
break;  

outputs the entire html-document instead of just the $csv variable which is supposed to print and save the .csv file for the client browser.

Ideas?

Note: the call is made from a php document -> posting -> $csv and $filename , they are both $_POST[].

2
  • Why is there an HTML document involved at all? Either you're outputting CSV or HTML, not both. Commented Nov 19, 2012 at 15:31
  • That's what im wondering, the variable only contains CSV-formatted data yet it the .csv file gets contains <html> and the CSV data. Commented Nov 19, 2012 at 15:33

1 Answer 1

3

Use exit instead of break!

Otherwise other code after this can be executed.

Sign up to request clarification or add additional context in comments.

3 Comments

I prefer die;. I can type a letter less.
it's in a switch case. break is usually standard?
The break there is correct in the context of switch. But It is also important that after delivering the file via header() to exit the code execution! So use exit; and after that break;.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.