如何检索<;text区域>;值,并保存到文件中


How to retrieve <textarea> value with POST and save to a file?

在"index.php"页面上,我有以下html:

<form class="centerd" method="post" action="upload.php" enctype="multipart/form-data">
    <textarea id="html" type="text" name="html-text"></textarea>
    <input type="submit" value="upload"/>
</form>

在"upload.php"页面上,我有以下php代码:

<?php
file_put_contents("/files/test.html", htmlspecialchars($_POST['html-text']));
?>
<h1>From the textbox:</h1>
<? echo htmlspecialchars($_POST['html-text']); ?>

我希望文本框中的文本显示在<h1>标记之后,并且我希望创建/files/test.html/files/已经存在),并且将文本框的文本放入test.html文件中。

实际发生的情况是,文本框中的内容显示在<h1>标记之后,但从未创建/files/test.html

看起来"/files/test.html"是一条绝对路径。你试过"files/test.html"吗?

很抱歉,我不能对布兰农的话发表评论,我只是还没有名声。但关键是:

有两种可能性:

  1. 正如布兰农所说->你的道路似乎是错误的
  2. 您没有在目录中写入(创建)文件的权限。根据我的经验,对于那些没有在htdocs文件夹中提供权限的Mac用户来说,这可能是一个常见的错误

您忘记了php!

不是:<? echo ?>但是:<?php echo ?>