开发者

PHP Write File Error

I have a page called index.php which is calling a function "writelog" in includes/Logger.php

I have file located at includes folder and code is as below.

function writelog($logText){
            $myFile = "testlog.txt";
            $fh = fopen($myFile, 'w') or die("can't op开发者_如何学Cen file");
            $stringData = $logText + "\n";
            fwrite($fh, $stringData);
            fclose($fh);
}

It shows errror "can't open file" . I have set FullPermission for everyone and still it says it cant access file.I tried to put file in same folder as index.php and same error. What can be possible cause ? Am I having wrong path ?


Try using the full path of the log file

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


I am assuming this file is also in includes, I'm guessing this is called from another script so the path would be one of the calling script. You can use this: $prevdir = getcwd(); chdir(dirname(__FILE__)); $myFile = "testlog.txt"; chdir($prevdir);

But it's best to use absolute paths

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜