【问题标题】:php save textarea to filephp 将文本区域保存到文件
【发布时间】:2018-07-13 00:30:44
【问题描述】:

我正在尝试重新制作脚本以将电话配置保存到服务器。我有一个脚本可以生成配置并在页面上显示它们的名称和代码。

看起来像这样:

<br>File:112233445566.cfg<br><textarea rows="50" cols="100">#!version:1.0.0.1
#File header "#!version:1.0.0.1" can not be edited or deleted.#
account.1.enable = 1
account.1.label = 123
account.1.display_name = 123
account.1.auth_name = 123
</textarea>
<br>File:112233445566.xml<br/><textarea rows="50" cols="100"><xxxIPPhoneDirectory>
</xxxIPPhoneDirectory>
</textarea><br/>`

如何将我在textarea中收到的信息保存在服务器文件夹中两个不同名称的不同文件(文件:xxxxxx.xxx)中?

https://pastebin.com/wSrfQGCt原文件代码

https://pastebin.com/9uqkRPmvhtml 中的结果页面

【问题讨论】:

    标签: php file directory save


    【解决方案1】:

    尝试使用 textarea 提交表单,然后:

    if($_SERVER['REQUEST_METHOD'] == 'POST'){
        if(isset($_POST['name_you_give_to_first_textarea']) && isset($_POST['name_you_give_to_second_textarea'])){
    
            #First file
            $handler = fopen('path/to/folder/file1.txt', 'w+'); #this creates the file if it doesn't exist
            $file1 = fwrite($handler, $_POST['name_you_give_to_first_textarea']);
            fclose($handler);
    
            #Second file
            $handler = fopen('path/to/folder/file2.txt', 'w+'); #this creates the file if it doesn't exist
            $file2 = fwrite($handler, $_POST['name_you_give_to_second_textarea']);
            fclose($handler);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-12-31
      • 1970-01-01
      • 2014-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多