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

问题描述:

嗨我使用fopen php函数来维护日志。我可以在我自己的电脑中写入文件。但是如何让PHP能够通过本地网络写文件。网络中的其他计算机通过IP访问我的计算机PHP应用程序,但在写入日志文件时未通过权限。我的代码是:使用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); 
    } 
} 

网络上的其他计算机会因'权限被拒绝'而出现错误。

+0

假设你不使用'localhost'?然后正确设置权限。 –

+0

我已经从文件系统读取了写入权限,但是它的权限被拒绝。 – user254153

+0

并分享权限?对于特定的用户帐户? –

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