再问:如何使用 php,以便当用户按下特定按钮时,他们可以写入特定的 .txt 文件?

发布于 2024-10-31 06:23:49 字数 839 浏览 2 评论 0原文

可能的重复:
如何使用 php,以便当用户按下特定按钮时,他们可以写入特定的 .txt 文件?

首先,我可以重新提出问题吗?我得到了两个答案,是的,但是我都尝试了,但都不起作用。我担心人们会忘记我的问题,而我可能永远无法得到问题的答案并修补我的代码。无论如何,就在这里。但是,如果重新提问违反了我不知道的某些规则,我将来会避免这样做。谢谢!

基本上,就像我问过的与我的 php 聊天应用程序相关的其他问题一样,我试图获取它,以便有一个文本字段,其中 $msg 通过 msg.txt 显示。两个用户可以通过这种方式相互通信。如果我想使用一个简单的包含函数,这会很容易。但我不想费尽心思制作所有这些页面并将其上传到我的服务器。那么,当用户(比如名为 Aaron)单击名为 Benjamin 的按钮并键入名为 aaronbenjamin.txt 的文件时,我该如何拥有它,并且如果 Aaron 想与另一个用户交谈,他可以按名为 Chris 的按钮,然后键入名为 aaronchris.txt 的文件?并且全部来自同一个框和文本字段?谢谢,我很感激。

关于我的问题,最重要的是用户可以按另一个用户的名字,并且他们将能够与该用户聊天。这意味着每当他们单击用户时,他们都会切换到不同的 .txt 文件。感谢@Cyclone 和@cronoklee 的回答,但遗憾的是他们没有工作。

Possible Duplicate:
How do I use php so that when a user presses a specific button, they can write to a specific .txt file?

First of all, am I able to re-ask a question? I got two answers, yes, but I tried both and they didn't work. I'm worried that people will forget about my question and I might not ever get the answer to my question and patch up my code. Anyway, here it is. If, however, re-asking questions is against some rule I was not aware of, I will refrain from this in the future. Thanks!

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.

The most important thing about my question was that the user is able to press the name of another user and they will be able to chat with the user. This means that they will be switching to a different .txt file whenever they click on a user. Thank you to @Cyclone and @cronoklee for your answers, but sadly they didn't work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫﹏色ふ单纯 2024-11-07 06:23:49

将其用于按钮:

<textarea name=msg></textarea>
<input type=submit name=file value=Aaron>
<input type=submit name=file value=Benjamin>

将其用于 PHP:

$fn = preg_replace('/\W+/', '', $_REQUEST["file"]);
file_put_contents("$fn.txt", $_REQUEST["msg"]);

Use this for the buttons:

<textarea name=msg></textarea>
<input type=submit name=file value=Aaron>
<input type=submit name=file value=Benjamin>

And this for the PHP:

$fn = preg_replace('/\W+/', '', $_REQUEST["file"]);
file_put_contents("$fn.txt", $_REQUEST["msg"]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文