PHP-如何在提交后添加内容

PHP - How to add content after submit

本文关键字:添加 提交 PHP-      更新时间:2023-09-26

我遇到困难。。。我正在尝试创建一个表单,在表单提交后自动创建额外的输入,如.php

<form>
     <input type="text" name="add" placeholder="Write Test">
     <br/>
     <input type="submit" name="submit" value="Send">
</form>

当用户输入"测试"并按下提交按钮时,将自动创建一个扩展,如下所示:

Test.php

提前谢谢。

这可以这样实现:

<?php
    if(!empty($_POST["add"])) {
        $file = $_POST["add"] . ".php";
        if(file_exists($file)) {
            echo "File already exists";
        } else {
            fopen($file, "w");
        }
    }
?>

参考文献:

检查文件是否已存在:http://php.net/manual/en/function.file-exists.php

创建文件/目录:http://php.net/manual/en/function.fopen.php

连接字符串:

$string = $_POST['add'];
$new_string = $string.'.php';