TransWikia.com

How to use the "Content-Disposition" header without auto-downloading the file?

Stack Overflow Asked by Mona on December 28, 2020

I’m using following code to display a .txt file in the browser (based on the GET request):

header('Content-type: text/plain; charset=UTF-8');
echo $LogUTF8;

Whenever I press CTRL+S to save the file, the default filename is the domain name, for example: "subdomain.example.com.txt".

I added the "Content-Disposition" to set the correct file name:

header('Content-Disposition: attachment; filename="test.txt"');

Unfortunately, then it automatically starts downloading the file, and I don’t want it to happen.

I can’t use the <title></title> tags when the Content-type is text/plain.

I also tried:

header('Content-Disposition: inline; filename="test.txt"');

But it doesn’t seem to work on Chrome-a-like browsers.

Is there any possibility to achieve the expected behaviour, without converting the text to HTML, adding extra "download" buttons, etc?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP