doujian0265 2012-06-22 16:33
浏览 113
已采纳

获取文本框文本

When I click the button the text from the textbox should be written to a .txt file, which then should be downloaded. Somehow the isset function doesn't work, I already tried to link the php file with a <form>, but then I can't read the textbox text.

Here's my code:

<?PHP

if(isset($_POST['submit']))
{
    $text = $_POST['text'];
    print ($text);

    $filename = 'test.txt';
    $string = $text;

    $fp = fopen($filename, "w");
    fwrite($fp, $string);
    fclose($fp);

    header('Content-disposition: attachment; filename=test.txt');
    header('Content-type: application/txt');
    readfile('test.txt');
}

?>

<html>
    <head>
        <title>Text Editor</title> 
    </head>
    <body>
        <textarea name="text" rows="20" cols="100"></textarea>
        <p>
        <button type="submit" value="submit">Download Text</button>
    </body>
</html>
  • 写回答

4条回答 默认 最新

  • douzao2992 2012-06-22 16:36
    关注

    Firstly, you need to have a <form> tag to be able to submit your data:

    <body>
    <form action="add your php filename here" method="post">
    
    ...
    
    </form>
    </body>
    

    You might also need to make your <button type="submit" into <input type="submit"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口