我在树莓派

时间:2020-09-29 01:53:44

标签: php html css

我正在创建一个网站,用户需要在该网站中将其姓名和姓氏提交到表单中,然后我需要它来创建一个文本文件,其中包含用户输入的内容并将其存储在服务器上。我要保存的位置在/var/www/html/text/fields.txt中的文件夹中 这是我要运行的代码。 1.HTML(sendmessage.html)2. PHP-(Action-page.php)

    <div class="messageform">
          <form action="action_page.php" method="post">
  First name:<br>
  <input type="text" name="firstname" value=""><br>
  Last name:<br>
  <input type="text" name="lastname" value=""><br><br>
  <input type="submit" value="Submit">
</form>
<?php
if( isset($_POST['firstname'] ) && isset( $_POST['lastname'] ) ) {
    // Manage our constants easier up top in one place
    $TextFilePath = './var/www/html/text';
    $FileName = 'fields.txt';
    $FullPathAndFileName = "$TextFilePath$FileName";

    // Create our data to write
    $txt = $_POST['firstname'].' - '.$_POST['lastname'] . PHP_EOL; 
    
    // Validate dir exists, if not, create it
    if (!is_dir($TextFilePath))
        mkdir($TextFilePath, 0755, true);

    // Open/create our file to write to
    $file = fopen($FullPathAndFileName, "w") or die("Can't find or create $FileName");

    // Write out the form data
    fwrite($file, $txt);

    // Close the file
    fclose($file);



}

请注意,HTML只是代码的一部分,而不是全部。

该代码在vs studio中可以工作,但是每当我在apache(raspberry pi)上运行它时,它似乎都可以工作,但是当我查看文件时,它永远不会被创建。

我们非常感谢您提供的帮助,只是为了让您知道我已经在线尝试了一些指南。

0 个答案:

没有答案
相关问题