我如何使用php,以便当用户按下特定按钮时,他们可以写入特定的.txt文件? [英] How do I use php so that when a user presses a specific button, they can write to a specific .txt file?

查看:66
本文介绍了我如何使用php,以便当用户按下特定按钮时,他们可以写入特定的.txt文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,就像我问过的其他有关php聊天应用程序的问题一样,我正在尝试获取它,以便有一个文本字段,其中$ msg通过msg.txt显示。两个用户可以通过这种方式与另一个用户通信。如果我想使用一个简单的include函数,这将很容易。但是我不想花所有的精力来制作所有这些页面并将其上传到我的服务器。因此,当用户名为Aaron的用户单击名为Benjamin的按钮并键入一个名为aaronbenjamin.txt的文件时,如果Aaron要与其他用户交谈,他可以按名为Chris的按钮,该怎么办? ,然后键入一个名为aaronchris.txt的文件?并且全部来自同一框和文本字段?谢谢,谢谢。

Basically, as in other questions I've asked related to my php chat application, I am trying to get it so that there is a text field where $msg is displayed via msg.txt. Two users can communicate to another in this way. This would be easy if I wanted to use a simple include function. But I don't want to take all the trouble to make and upload all those pages to my server. So how can I have it where when the user, say named Aaron, clicks on a button titled Benjamin, and types to a file called aaronbenjamin.txt, and if Aaron wants to talk to another user, he can press on a button titled Chris, and type to a file called aaronchris.txt? And all from the same box and text field? Thanks, I appreciate it.

编辑:这是我的代码-

http://key-mail.zxq.net/msg.txt

推荐答案

这是如何写入文件的方法:
http://php.net/manual/en/function.fopen.php

This is how to write to a file: http://php.net/manual/en/function.fopen.php

最好使用

要使不同的链接执行不同的操作,可以按照建议的方式使用AJAX,也可以使用GET变量在PHP端路由函数。后者比较容易,但是这意味着您需要在用户按下按钮后重新加载页面。

To make different links do different things, you can use AJAX as you suggested or you can use GET variables to route functions on the PHP side. The latter is easier but means you will need to reload the page after the user presses the button.

这是一个小演示:

<a href="thispage.php?clicked=1">click here</a>

然后在php页面顶部:

then at the top of the page in php:

 if($_GET['clicked']==1){--write to file1---}
 else if($_GET['clicked']==2){--write to file2---}

希望有帮助

这篇关于我如何使用php,以便当用户按下特定按钮时,他们可以写入特定的.txt文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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