1

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.

Wulf
  • 31
  • 3
  • Possible duplicate of [How to Automatically Start a Download in PHP?](https://stackoverflow.com/questions/40943/how-to-automatically-start-a-download-in-php) – BlackNetworkBit Sep 22 '18 at 14:21
  • Try and change the content type to `application/octet-stream` instead of `text/txt` (which seems like an odd content type) and see if it works then. – M. Eriksson Sep 22 '18 at 14:21
  • application/octet-stream doesn't work, I tryed it befor. – Wulf Sep 22 '18 at 14:26

0 Answers0