With this little function I want to create a txt-file and command the browser to start the download. The god news is, it works on my XAMPP. The bad news is, it doesen‘t work on my webserver. Instead of starting the Download, the file is displayed on the browser. What did I wrong?
public function sendAsFile() {
while (false !== ob_get_clean()) { };
header('Content-Type: text/plain; charset=utf-8');
header('Content-Disposition: attachment; filename="export.txt"');
echo $this->getString();
}
This question How to Automatically Start a Download in PHP? doesn't fixed my problem. That only works with a File on the Server, but i dont want to store every created file on my webspace. I want to create and download it immediately. I'm wondering cause it works on XAMPP but not in the WWW.