我正在研究如何从字符串创建文件的方法,这可能是纯文本将另存为 .txt 和 php 为 .php 等,但我希望能对此有所了解
**我找到了这段代码
$file = 'people.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current .= "John Smith\n";
// Write the contents back to the file
file_put_contents($file, $current);
但是我需要将 people.txt 保存在我的服务器上吗?
强制下载部分
header("Content-Disposition: attachment; filename=\"" . basename($File) . "\"");
header("Content-Type: application/force-download");
header("Content-Length: " . filesize($File));
header("Connection: close");
我需要在哪里存放上述内容,我假设代码是正确的,可以强制下载我的现成文件?