简体   繁体   English

如何使用PHP保存文件?

[英]How to save a file using PHP?

I'm currently making subscribe form, I got the HTML ready but I got problems in the PHP:我目前正在制作订阅表格,我准备好了 HTML,但我在 PHP 中遇到了问题:

<?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
?>

Now I got them using php, how can I save them.现在我使用 php 获取它们,我该如何保存它们。

I need like to save them anywhere so I can like check them anytime.我需要把它们保存在任何地方,这样我就可以随时查看它们。

like I would open a .txt where it saves and then I find the list of emails and names and messages.就像我会打开一个 .txt 文件保存在那里,然后我会找到电子邮件、姓名和消息的列表。

I agree with @prakhar19, a database is better suited to store this kind of info.我同意@prakhar19,数据库更适合存储此类信息。 But if you really want to store this information in a file on the server (because you don't want to setup a database server just for this), go for file_put_contents :但是,如果您真的想将此信息存储在服务器上的文件中(因为您不想为此设置数据库服务器),请使用file_put_contents

file_put_contents('subscribers.txt',
    $_POST['name'] . '\n' . $_POST['email'] . '\n' . $_POST['message'],
    FILE_APPEND);

You need to make a database for saving the info.您需要创建一个数据库来保存信息。 Google for ' Databases ' and ' MySql '.谷歌搜索“ Databases ”和“ MySql ”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM