create and download text file in php

Solutions on MaxInterview for create and download text file in php by the best coders in the world

showing results for - "create and download text file in php"
Luciano
27 Nov 2019
1$file = "test.txt";
2$txt = fopen($file, "w") or die("Unable to open file!");
3fwrite($txt, "lorem ipsum");
4fclose($txt);
5
6header('Content-Description: File Transfer');
7header('Content-Disposition: attachment; filename='.basename($file));
8header('Expires: 0');
9header('Cache-Control: must-revalidate');
10header('Pragma: public');
11header('Content-Length: ' . filesize($file));
12header("Content-Type: text/plain");
13readfile($file);