Search code examples
phpfilecontent-dispositionsave-as

PHP: Save as dialog with custom content


I have the following code:

header('Content-type: text/plain');
header("Content-Disposition: attachment; filename=bookmark.adr");
readfile('bookmark.adr');

This makes a save-as popup where an user can save the bookmark.adr file. But I would like to custom generate the content of that file. How can I generate the content and let that file be popupped as save-as?

Thanks!


Solution

  • Just don't do readfile(). Echo out whatever you want that file to contain instead.

    Your Content-Disposition header is what will tell most browsers to prompt the user to save the file.