使用php无法将textarea保存到文件中? [英] Can't save textarea to file using php?

查看:229
本文介绍了使用php无法将textarea保存到文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有文件保存textarea的问题。我用POST方法发送表单到另一个页面,然后在下一页我不能包含文件的textarea内容我不知道是什么问题。



这里有两页:
page1:

 <!DOCTYPE HTML> 
< html>
< head>
< title>储存< / title>
< / head>

< body>
< form action =page2.phpmethod =post>
< span>名称:< / span>
< input type =textname =name>< br>
< span>文件扩展名:< / span>
< select name =extid =ext>
< option value =。txt> .txt< / option>
< option value =。doc> .doc< / option>
< / select>
< textarea name =txt1id =txt1cols =15rows =10>< / textarea>
< br>
< input type =submitname =submitid =submitvalue =Save>
< / form>
< br>
< / body>

< / html>

-page2.php

  $ txt1 = $ _POST ['txt1']; // textarea 
$ name = $ _POST ['name'];
$ ext = $ _POST ['ext']; //从多个扩展中选择
if($ ext =='.txt')//如果我想添加多个扩展。
{
$ file ='。$ name $ ext。';
$ output =$ txt1;
file_put_contents($ file,$ output);
$ text = file_get_contents($ file);

header(Content-Description:File Transfer);
header(Content-Type:application / text / plain);
header(Content-Disposition:attachment; filename =。basename($ file));
ob_clean();
flush();
readfile($ file);
退出;
}


解决方案

尝试使用wrap元素你的textarea

 < textarea name =txt1id =txt1cols =15rows =10> ;< / textarea的> 

添加换行

 < textarea name =txt1id =txt1cols =15rows =10wrap =virtual>< / textarea> 

您也可以使用wrap:off,hard,soft和physical

在数据库中确保字段txt1被正确定义(即输入文本)。


I have issue saving textarea to file. I used POST method to send the form to the other page then, in the next page I can't include the textarea content with the file Im not sure what is the problem.

Is there any idea about what is the problem?

Here are the two pages: page1:

<!DOCTYPE HTML>
<html>
<head>
    <title>Save</title>
</head>

<body>
    <form action="page2.php" method="post">
    <span>name:</span>
    <input type="text" name="name"><br>
    <span>file extension: </span>
    <select name="ext" id="ext">            
        <option value=".txt">.txt</option>
        <option value=".doc">.doc</option>          
    </select>
    <textarea name="txt1" id="txt1" cols="15" rows="10"></textarea>
    <br>
          <input type="submit" name="submit"  id="submit" value="Save">
          </form>
          <br>
</body>

  </html>

-page2.php

$txt1 = $_POST['txt1']; //textarea
$name = $_POST['name'];
$ext = $_POST['ext'];  //choose from multiple extensions
if ($ext == '.txt')    // In case if I want to add more than extension.
{   
    $file = "'. $name$ext.'" ;
    $output = "$txt1";
    file_put_contents($file, $output);
    $text = file_get_contents($file);

    header("Content-Description: File Transfer");
    header("Content-Type: application/text/plain");
    header("Content-Disposition: attachment; filename=".basename($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}

解决方案

Try using the wrap element in your textarea

<textarea name="txt1" id="txt1" cols="15" rows="10"></textarea>

add wrap

<textarea name="txt1" id="txt1" cols="15" rows="10" wrap="virtual"></textarea>

you can also use wrap: off, hard, soft and physical

In your database make sure the field txt1 is defined properly (i.e type text).

这篇关于使用php无法将textarea保存到文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆