0

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 open 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 ?

2 Answers 2

1

Try using the full path of the log file

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.