【问题标题】:File handling with PHP over local network通过本地网络使用 PHP 处理文件
【发布时间】:2017-10-25 15:49:05
【问题描述】:

您好,我正在使用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);
  }
}

网络上的其他计算机收到“权限被拒绝”错误。

【问题讨论】:

  • 假设您没有在这些上使用localhost?然后正确设置权限。
  • 我有文件系统的读写权限,但它的说权限被拒绝。
  • 和共享的权限?对于特定的用户帐户?
  • 每个人都有读取和执行权限。如何也给予写权限。

标签: php file-permissions fopen


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2014-02-25
    • 2021-01-17
    • 1970-01-01
    • 2013-05-04
    • 2017-05-11
    • 1970-01-01
    • 2018-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多