I have a php file which is meant to serve a CSV download.
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename=users.csv');
echo $csvOut;
Where $csvOut is a string I generated in another function.
The problem is that when I navigate to this PHP file, my browser gives me a 404 file not found error. It does the same thing when I remove the header('Content-Disposition: attachment;filename=users.csv'); line as well.
However, I noticed that if I change header('Content-Type: text/csv'); to header('Content-Type: text/html'); it displays the contents of $csvOut on the screen but ONLY if header('Content-Disposition: attachment;filename=users.csv'); has been removed.
This is really confusing me as I have successfully used this code to serve CSV files before and I can't see what I'm doing (or not doing) which is breaking it.
Any help would be greatly appreciated!