I'm trying to do a simple download of a file in php. Actually it's a .csv-file, but it seems I can't even download a regular text file. I found the following code...
$mytext = "some text";
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename='whatever.txt'");
echo $mytext;
...but when I add it to my php file, there is no download being initialized, but the text of $mytext (i.e. "some text") is just simply displayed within my HTML text. I am running the whole thing in wordpress, if that might be important. Any idea?
Edit: I tried the solution from php, file download but this wasn't working at all for me. I guess, there's a problem with the headers. Since I use the php script inside my wordpress environment, I think he headers I set, are ignored - and that's why the file is interpreted as text instead as a downloadable file. Is there any way to ignore the wordpress header or force the custom header somehow?