我正在研究如何从字符串创建文件的方法,这可能是纯文本将保存为.txt和PHP为.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");
哪里需要房子上面,我假设的代码是正确的,迫使我下载现成的文件?
简短的回答:不,你并不需要先创建一个文件。无论你在阅读不存在的文件。看看'fopen($文件,'w +')'而不是。之后,您只需在强制下载标题后回显您的字符串。 – h2ooooooo 2013-02-25 09:45:36