how to map the path to the file easily?
public_html/api/function.php
<?php
function writetologfile($content)
{
$filename = 'logfile/testing_randomstring.txt';
if (!$handle = fopen($filename, 'a'))
{
echo "Cannot open file ($filename)";
exit;
}
fclose($handle);
}
?>
the actual path of the text file is in public_html/r/admin/logfile/testing_randomstring.txt
so if I run the script at public_html/folder1/folder2/addlog.php
, it won't be able to find the path to the testing_randomstring.txt
addlog.php
<?php
include("../../api/function.php");
writetologfile('hahaha');
?>
How I can able to easily point to this text file path, no matter where my php calling script is from.
I tried to change $filename = 'logfile/testing_randomstring.txt'; inside writetologfile function by enforcing it to absolute fix path, something like $filename='/r/admin/logfile/testing_randomstring.txt', but it is not working