通过本地网络使用PHP进行文件处理

时间:2017-05-25 05:32:07

标签: php file-permissions fopen

您好我使用fopen php函数来维护日志。我可以在自己的计算机上写入文件。但是如何让PHP能够通过本地网络写入文件。网络中的其他计算机通过IP访问我的计算机PHP应用程序但在写入日志文件时失败并有权限。我的代码是:

function hotellog($txt) {
   date_default_timezone_set("Asia/Kathmandu");
   $newfile = '\\localhost\gandaki/wp-content/hotel_log.json';
   if (file_exists($newfile)) {
      $myfile = fopen($newfile, "a") or die("Unable to open file!");
      $txt = date("Y-m-d h:i:s") . "\r\t\t" . $txt . "\n\n\n";
      fwrite($myfile, $txt);

      fclose($myfile);
   } else {
      $myfile = fopen($newfile, 'w') or die("Can't create file");
      $txt = date("Y-m-d h:i:s") . "\r\t\t" . $txt . "\n\n\n";
      fwrite($myfile, $txt);

      fclose($myfile);
  }
}

网络上的其他计算机将错误视为“权限被拒绝”。

1 个答案:

答案 0 :(得分:0)

在正常情况下,PHP无法(好吧,不应该)能够通过网络将文件写入您的计算机。最好在本地计算机上写日志文件,然后通过sftp或类似的东西从本地计算机到远程计算机编写文件传输脚本。

相关问题