2011-09-03 81 views
0

我有一個頁面調用的index.php這是在調用一個函數「WRITELOG」包括/ Logger.phpPHP寫文件錯誤

我已經文件位於包含文件夾,代碼如下所示。

function writelog($logText){ 
      $myFile = "testlog.txt"; 
      $fh = fopen($myFile, 'w') or die("can't open file"); 
      $stringData = $logText + "\n"; 
      fwrite($fh, $stringData); 
      fclose($fh); 
} 

它顯示errror「無法打開文件」。我爲每個人設置了FullPermission,但它仍然無法訪問文件。我試圖將文件放在與index.php相同的文件夾中,並且出現同樣的錯誤。可能的原因是什麼?我錯了路嗎?

回答

1

嘗試使用日誌文件

$myFile = "/full/path/to/testlog.txt";

0

我假設這個文件也包括我猜這是從另一個腳本調用這樣的路徑將是一個完整路徑調用腳本。你可以用這個: $prevdir = getcwd(); chdir(dirname(__FILE__)); $myFile = "testlog.txt"; chdir($prevdir);

但是最好用絕對路徑