开发者

Re-ask: How do I use php so that when a user presses a specific button, they can write to a specific .txt file? [duplicate]

开发者 https://www.devze.com 2023-02-23 13:55 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: How do I use php so that when a user presses a specific button, they can write to a specific .txt file?
This question already has answers here: Closed 11 years ago.

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 an开发者_JAVA百科d 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.


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"]);
0

精彩评论

暂无评论...
验证码 换一张
取 消