php
  • file-permissions
  • fopen
  • 2017-05-25 41 views 0 likes 
    0

    嗨我使用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

    並分享權限?對於特定的用戶帳戶? –

    回答

    0

    在正常情況下,PHP不能(通過,不應該)能夠通過網絡將文件寫入到您的計算機上。你最好在本地計算機上寫日誌文件,然後通過sftp或類似的方式從本地計算機向遠程計算機發送文件傳輸腳本。

    相關問題