PHP如何在每次用户单击按钮时创建新文件
问题描述:
So basically what I want is a program where the user inputs something in a textarea, the php then stores the input in a new file every time this is done. Here is what I've got so far:
This gets the input from the user.
<?php
$usrUp = $_POST['input'];
$fOp = fopen("updates.txt","c+");
fwrite($fOp, $usrUp);
fclose ( $fOp );
?>
And this is supposed to create a new file with the new information.
<?php
if (file_exists ("updates.txt") && filesize ("updates.txt") > 0)
{
$open = fopen("updates.txt","r");
$contentU = fread($open, filesize("updates.txt"));
fclose ($open);
echo $contentU;
}
?>
答
To make each time a new file you could use time():
// change this line of code
$fOp = fopen("updates.txt","c+");
to:
$file_name = "updates_".time().".txt";
$fOp = fopen($file_name,"c+");