简体   繁体   English

如何取回<textarea> POST 值并保存到文件?

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

On the page "index.php", I have the following html:在页面“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>

On the page "upload.php", I have the following PHP code:在“upload.php”页面上,我有以下 PHP 代码:

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

I want the text from the textbox to show up after the <h1> tag, and I want /files/test.html to be created ( /files/ already exists), and the text from the textbox to be put into the test.html file.我想从文本框中的文本后展现出来<h1>标签,我想/files/test.html要创建( /files/已经存在),并从文本框中的文本被放入的test.html文件。

What actually happens, is whatever is in the textbox shows up after the <h1> tag, but /files/test.html is never created.实际发生的是,文本框中的内容显示在<h1>标记之后,但从未创建/files/test.html

It looks like "/files/test.html" is an absolute path. 看起来"/files/test.html"是绝对路径。 Have you tried "files/test.html" ? 您是否尝试过"files/test.html"

I'm sorry that I cannot comment on what Brannon said, I simply don't have reputation for it yet. 对不起,我无法评论布兰农所说的话,我只是还没有声望。 But to the point: 但是要点:

There are two possibilities: 有两种可能性:

  1. As Brannon said -> your path seems to be wrong. 正如布兰农所说->您的道路似乎是错误的。
  2. You don't have permission to write (create) files in your directory. 您无权在目录中写入(创建)文件。 This can, in my experience, be a common error for Mac users who haven't provided permission in their htdocs folder. 以我的经验,这可能是Mac用户在htdocs文件夹中未提供权限的常见错误。

you forgot the php!你忘记了php!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM