我想知道每次有人点击按钮时我是否可以创建一个新的php文件。按钮看起来像这样:
<button onClick="generate.php"> Generate </button>
PHP:
What do I do here?
我希望生成的页面是每按一次按钮的数字。因此,已生成50个页面,因此下一次单击会生成名为&#34; 51.html&#34;的文件,依此类推。
我知道对于日志,你必须做这样的事情:
<?php
$file = fopen('countlog.txt', 'r');
$dat = fread($fil, filesize('./class/countlog.txt'));
$write = fwrite($file, $data+1);
echo $data;
fclose($file);
?>
答案 0 :(得分:1)
试试这个
<?php
define('START_FILENAME', __DIR__ . "/starting_point");
if (file_exists(START_FILENAME))
{
# There is that File - read its content
$start = (int) file_get_contents(START_FILENAME);
}
else
{
# No File Found - Create new File
$start = 0;
@file_put_contents(START_FILENAME, "$start");
}
# When Form Submitted
if (isset($_POST) and isset($_POST['Click']) and $_POST['Click'] == "Generate")
{
$file_name = "{$start}.html";
@file_put_contents($file_name, "Hello World!");
# Update Counter too
$start = $start + 1;
@file_put_contents(START_FILENAME, "$start", 0);
echo "Generated Filename - $file_name";
}
?>
<form action="demo.php" method="post" accept-charset="utf-8">
<input type="submit" name="Click" value="Generate">
</form>