I have a PHP script that create a text file using the file_put_contents() function. It goes simply like this:
$mytext = "sample text";
file_put_contents('my_new_file.txt', $mytext);
The issue is that I would like the file to be downloaded by the user Download folder and not the website Root folder.
So my question is: How to send the newly created text file to the user computer?
Create the file, then use header() to redirect the user.
<?php
$mytext = "sample text";
file_put_contents('my_new_file.txt', $mytext);
header("Content-Type: text/plain");
header("Location: my_new_file.txt");
?>