php将textarea保存到文件中

时间:2018-02-02 13:33:14

标签: php file directory save

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

看起来像这样:

<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/9uqkRPmv html中的结果页

1 个答案:

答案 0 :(得分:0)

尝试使用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);
    }
}